That's pretty easy. You can use two nested for
loops on the commandline:
for %x in (*) do @(
for %y in (*) do @(
if not "%x"=="%y" @(
fc /b "%x" "%y" >nul && echo "%x" and "%y" are equal
)
)
)
If you want to use this in a batch file, you need to double the %
signs.
The code simply loops twice over all files in the current directory:
for %x in (*) do @(
for %y in (*) do @(
then, if the two file names aren't equal (because then we know the files are equal)
if not "%x"=="%y" @(
if runs the fc
utility which compares files
fc "%x" "%y" >nul && echo "%x" and "%y" are equal
If fc
had an exit code of 0
it means that the files were equal (thus duplicates) and in that case the echo
after the &&
is triggered. &&
means “Just execute the following command if the previous one exited with a 0
exit code”.
And for 30 files this is certainly fast enough. I once implemented something more elaborate in batch, but this should suffice.
ETA: Found the other batch; still nowhere publicly explained but I once posted it at Super User.