@if (@CodeSection == @Batch) @then
@echo off
color 1a
setlocal EnableExtensions
setlocal DisableDelayedExpansion
echo Select PRIMARY folder
for /F "delims=" %%S in ('CScript //nologo //E:JScript "%~F0"') do (
set srce=%%S
)
if "%srce%"=="" goto :End2
echo Selected folder: "%srce%"
echo Select folder to COMPARE
for /F "delims=" %%D in ('CScript //nologo //E:JScript "%~F0"') do (
set dest=%%D
)
if "%dest%"=="" goto :End2
echo Selected folder: "%dest%"
if "%srce%"=="%dest%" goto :End1
echo.
echo The following prompt asks you for a folder to move duplicates to.
echo.
echo ---- HOWEVER, THIS COMMAND FILE DOES NOT MOVE THEM ----
echo.
echo The path is written to the logfile so it can be run separately if
echo required.
echo.
echo Select folder to MOVE duplicates to
for /F "delims=" %%S in ('CScript //nologo //E:JScript "%~F0"') do (
set mdest=%%S
)
if "%mdest%"=="" goto :End2
echo Selected folder: "%mdest%"
set /P como=Copy or Move Duplicates (Set in logfile) [ENTER = Copy]:
echo.
echo If you just want to match on Size, Date, and Name just hit
echo ENTER at the next prompt.
echo If you want to do a binary compare also, enter any character.
echo.
set /P cbin=Do binary compare [ENTER = No]:
:GetExt
echo.
set /P ext=Please enter extension [eg. jpg, * = ALL] ENTER to exit:
if not defined ext goto :End2
set /a totfiles=0
set /a matchfiles=0
call :SetLogfile %~dp0%
echo @echo off >"%logfile%"
echo echo %date% %time% >>"%logfile%"
for /r "%srce%" %%a in (*.%ext%) do (call :CheckSize "%dest%" %%~za "%%~fa")
:End
echo Total files: %totfiles%
echo Matching files: %matchfiles%
if %matchfiles% equ 0 (echo Matching files: 0 >>"%logfile%")
set totfiles=
set matchfiles=
set ext=
if exist "%logfile%" call :ViewLog
goto :GetExt
:End1
color 1c
echo **** SOURCE and DESTINATION are the same! ****
:End2
set srce=
set dest=
pause
rem exit
:SetLogfile
set "logfile=%~1FCompare-%time:~0,2%%time:~3,2%%time:~6,2%.cmd"
goto :EOF
:ViewLog
set /p view=View logfile [y,n]
if "%view%"=="y" (start notepad.exe "%logfile%")
set view=
goto :EOF
:CheckSize
set /a totfiles+=1
for /r %1 %%b in (*.%ext%) do (
if %2==%%~zb (
echo.
echo Comparing: "%~3" "%%~b"
echo Sizes: Match
call :CheckDate "%~3" "%%~b"
)
)
goto :EOF
:CheckDate
if "%~t1" equ "%~t2" (
echo Dates: Match
call :CheckName "%~1" "%~2"
)
goto :EOF
:CheckName
if "%~nx1" equ "%~nx2" (
echo Names: Match
if not defined cbin (
call :Matching "%~1" "%~2"
) else (
call :CheckBin "%~1" "%~2"
)
)
goto :EOF
:CheckBin
.\cmp.exe -s "%~1" "%~2"
if errorlevel 0 (
echo Binaries: Match
call :Matching "%~1" "%~2"
)
goto :EOF
:Matching
set /a matchfiles+=1
echo echo "%~1" matches "%~2" >>"%logfile%"
set tdir=%~dp2
set tdir=%tdir:~0,-1%
set tdir2=%tdir:~2%
if not defined como (
echo robocopy "%tdir%" "%mdest%%tdir2%" "%~nx2" >>"%logfile%"
) else (
echo robocopy "%tdir%" "%mdest%%tdir2%" "%~nx2" /MOV >>"%logfile%"
)
echo.
goto :EOF
endlocal
End of Batch section
@end
// JScript section
// Creates a dialog box that enables the user to select a folder and display it.
var title = "Select a folder", rootFolder = 0x11;
var shl = new ActiveXObject("Shell.Application");
var folder = shl.BrowseForFolder(0, title, 0, rootFolder);
WScript.Stdout.WriteLine(folder ? folder.self.path : "");