Laurent Jumet
2012-09-25 08:16:53 UTC
Hello !
I'm unsuccessfully trying to make a batch that searchs a directory looking for file with different name but same size, and delete one of them.
This batch almost works, but it doesn't detect the secund file with the same size.
=== Begin DUPEVID.BTM ===
setlocal
if not ISDIR H:\prov GOTO FAIL1
pushd H:\prov
DIR /B /Os *.flv | for %loop in (@con) gosub dupe_strip
DIR /B /Os *.mp4 | for %loop in (@con) gosub dupe_strip
DIR /B /Os *.wmv | for %loop in (@con) gosub dupe_strip
DIR /B /Os *.avi | for %loop in (@con) gosub dupe_strip
ENDLOCAL
QUIT
:dupe_strip
set first=%@findfirst[%loop]
set second=%@findnext[]
if "%second" == "" return
IFF %@filesize[%first] EQ %@filesize[%second] THEN
SET delete=(%second)
ELSE
RETURN
ENDIFF
:: the next routine will delete the duplicate file.
del %delete
RETURN
:FAIL1
PAUSE Le dossier n'existe pas...
POPD
endlocal
QUIT
=== End DUPEVID.BTM ===
I'm unsuccessfully trying to make a batch that searchs a directory looking for file with different name but same size, and delete one of them.
This batch almost works, but it doesn't detect the secund file with the same size.
=== Begin DUPEVID.BTM ===
setlocal
if not ISDIR H:\prov GOTO FAIL1
pushd H:\prov
DIR /B /Os *.flv | for %loop in (@con) gosub dupe_strip
DIR /B /Os *.mp4 | for %loop in (@con) gosub dupe_strip
DIR /B /Os *.wmv | for %loop in (@con) gosub dupe_strip
DIR /B /Os *.avi | for %loop in (@con) gosub dupe_strip
ENDLOCAL
QUIT
:dupe_strip
set first=%@findfirst[%loop]
set second=%@findnext[]
if "%second" == "" return
IFF %@filesize[%first] EQ %@filesize[%second] THEN
SET delete=(%second)
ELSE
RETURN
ENDIFF
:: the next routine will delete the duplicate file.
del %delete
RETURN
:FAIL1
PAUSE Le dossier n'existe pas...
POPD
endlocal
QUIT
=== End DUPEVID.BTM ===
--
Laurent Jumet - Point de Chat, Liège, BELGIUM
KeyID: 0xCFAF704C
[Restore address to laurent.jumet for e-mail reply.]
Laurent Jumet - Point de Chat, Liège, BELGIUM
KeyID: 0xCFAF704C
[Restore address to laurent.jumet for e-mail reply.]