Microsoft Bob

Just a short, simple blog for Bob to share some tips and tricks.

Be sure to check out my non-technical blog at

Month List

Batch File: Delete Duplicate Files

Using this Batch File

Some time ago a friend of mine gave me a bunch of JPG files, but for some reason she had two copies of every image in the collection. The names of the images had all been randomized, and since there were hundreds of files in the collection it would have taken hours to find and delete the duplicates. With that in mind, I wrote the following batch file that loops through the collection of files and does a binary comparison to find and delete duplicate files.

To use the example code, copy the batch file code from below into Notepad and save it as "_del_dupes.cmd" in the folder where you have duplicate files

Note: As with many utilities that I write - this is a destructive operation, meaning that it will delete files without prompting, so you should always make a backup just in case something goes terribly wrong... ;-]

Batch File Example Code

@echo off

dir *.jpg /b > _del_dupes.1.txt

for /f "delims=|" %%a in (_del_dupes.1.txt) do (
   if exist "%%a" (
      dir *.jpg /b > _del_dupes.2.txt
      for /f "delims=|" %%b in (_del_dupes.2.txt) do (
         if not "%%a"=="%%b" (
            echo Comparing "%%a" to "%%b"...
            fc /b "%%a" "%%b">NUL
            if errorlevel 1 (
               echo DIFFERENT
            ) else (
               echo SAME
               del "%%b"

del _del_dupes.?.txt
Posted: Dec 24 2008, 14:27 by Bob | Comments (3)
  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
Filed under: Windows
Social Bookmarks: E-mail | Kick it! | DZone it! |

Comments (3) -

John Smith Denmark said:

Thanks man I was wondering how to done this after see freeware application from

# July 24 2012, 04:28

Henrie Russia said:

Nice way for the geeks Smile
The better way is to use Image Comparer and Audio Comparer that are available at

# March 09 2013, 06:25

markbun Philippines said:

Another alternative for this issue is "DuplicateFilesFinder" An easy fix for duplicates.

# June 14 2013, 16:33
Comments are closed