Page 1 of 1

Remove duplicate file. Add filesize test.

Posted: 03 May 2007 13:02
by budhax
Hello,
Here is a script that remove all files in Folder1 if this file exists in Folder2.
So, it does something like: Folder1 - Folder2
in other words, it removes duplicate files.
This script test only the filename: remove the file in Folder1 if the same filename is present in Folder2.
I would to improve it, adding a size file test. remove the file only filesize of both files are the same.
Do you have an idea ?
My line ECHO %%~zf cannot display the file size !!!

F1-F2.bat

Code: Select all

SET Fold1=.\Folder1
SET Fold2=.\Folder2
FOR /F "Delims=" %%f in ('DIR  /b /on "%Fold2%\*.*"') DO (
   IF EXIST "%Fold1%\%%f" DEL /F /Q "%Fold1%\%%f"
   REM ECHO %%~nf  ---  %%~zf
)


Put the script next Folder1 and Folder2.
Thanks

Posted: 10 May 2007 22:12
by DosItHelp
budax,
For a precise file compare you can use the FC command and process the result (success or fail) to invoke the delete like this:

Code: Select all

SET Fold1=.\Folder1
SET Fold2=.\Folder2
FOR /F "Delims=" %%f in ('DIR  /b /on "%Fold2%\*.*"') DO (
   FC /b "%Fold1%\%%f" "%Fold2%\%%f">NUL&&(
      echo.DEL /F /Q "%Fold1%\%%f"
   )
)


Hope it DOS help :D