1

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!

songa
  • 53
  • 2
  • 10
  • 1
    Did you try something ? – SachaDee Jun 27 '15 at 20:23
  • Yes, I did, but as msdos I do not quite understand, I tried looking for something in google, but as not found, I'm trying some help here! – songa Jun 27 '15 at 20:27
  • 1
    I don't understand why some people think this question is "too broad" when the request is perfectly defined and there is already a ten-lines solution that gives exactly the requested result... **`:(`** – Aacini Jun 30 '15 at 02:45
  • Don't worry Aacini... What matters is that you know the answer and sees no obstacles to share it with those who not know... Until even when looks like a simple homework. I hope one day I can do the same for you! :) – songa Jun 30 '15 at 04:57

1 Answers1

5

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.

Community
  • 1
  • 1
Aacini
  • 65,180
  • 12
  • 72
  • 108
  • thank you very much Aacini, I tested the script and it works well... if you allow, I will adjust it so that I can identify both identical files. It show only one of the two (or more). As now I have a reference you gave me, I can give of the rest alone! thank you very much. – songa Jun 27 '15 at 21:59
  • excuse me Aacini, but my reputation not allow me to spice up your post! :( – songa Jun 27 '15 at 22:04
  • I tested the code and works correctly here. Be aware that the names of files with same size are separated by a single comma, that may go unnoticed... Try to separate the names in a more visible way; for example: `set "size[%%~Za]=!size[%%~Za]!, "%%~Fa""` – Aacini Jun 27 '15 at 22:13
  • ooppzzzzz, sorry me again... I had not noticed, but both files appear separated by a comma! I do not need to change anything! :) – songa Jun 27 '15 at 22:16