songa
songa

Reputation: 53

Windows batch file to find duplicates size files in harddisk (no matter the name and the extension)

I'd like a batch file ( Windows CMD is the interpreter, a .bat ) to do this type of task:

1) Search through a folder and its subfolders (entire harddisk)

2) Find files with the same size (no matter filename and extension)

3) Display these files (or not)

Thank you for any kind of help! :)

EDIT:

With the following commands, I can know all sizes that the files have...

@echo off
set "filename=*.*"
for %%A in (%filename%) do echo.Size of "%%A" is %%~zA bytes

but now the big problem is that you need to compare the first, with the remainder and so on!

Upvotes: 1

Views: 1778

Answers (1)

Aacini
Aacini

Reputation: 67236

The Batch file below should solve your problem; however, be aware that in despite of its apparent simplicity, it is based on advanced concepts, like array management in Batch files.

@echo off
setlocal EnableDelayedExpansion

rem Group all file names by size
for /R %%a in (*.*) do (
   set "size[%%~Za]=!size[%%~Za]!,%%~Fa"
)

rem Show groups that have more than one element
for /F "tokens=2,3* delims=[]=," %%a in ('set size[') do (
   if "%%c" neq "" echo [%%a]: %%b,%%c
)

This program may take too much time if the number of files is large or if the starting folder have a long path.

Upvotes: 5

Related Questions