11

I want to compare two folders on Windows (Vista, XP) which have a large number of huge files, which I need to compare. If I use Beyond Compare or such tool to compare the folders, it is taking a lot of time if I do it manually. I need to add that folder comparison to batch file.

So on Windows (XP, Vista), is there any command (built-in) or any 3rd party tool/utility (commercial or freeware - either) to compare two folders using the command line.

Ross Ridge
  • 38,414
  • 7
  • 81
  • 112
goldenmean
  • 18,376
  • 54
  • 154
  • 211

6 Answers6

15
>diff -r Folder_A Folder_B

You may find GNU diffutils compiled for windows at GnuWin32.

ephemient
  • 198,619
  • 38
  • 280
  • 391
  • 2
    See https://stackoverflow.com/a/2019897/4304516 for useful options you can add to this command. – hb20007 Jul 10 '20 at 10:00
11

There is the built in command COMP that you could use. It depends a little bit on what you actually want to compare.

Compares the contents of two files or sets of files.

COMP [data1] [data2] [/D] [/A] [/L] [/N=number] [/C]

data1 Specifies location and name(s) of first file(s) to compare.

data2 Specifies location and name(s) of second files to compare.

/D Displays differences in decimal format.

/A Displays differences in ASCII characters.

/L Displays line numbers for differences.

/N=number Compares only the first specified number of lines in each file.

/C Disregards case of ASCII letters when comparing files.

To compare sets of files, use wildcards in data1 and data2 parameters.

Use a syntax like COMP c:\folder1 c:\folder2 to compare all files in folder1 with the content of folder2. If you need to recurse into the subdirectories, you need to use a batch script using a FOR loop and the PUSHD and POPD command.

Just leave a comment, if you need help with that.

Frank Bollack
  • 24,478
  • 5
  • 49
  • 58
  • how to use this `COMP` for recursively with two folder. I tried like this `COMP C:\folder1\* C:\folder2\*` but this does not return all file. – Ramesh Aug 05 '13 at 06:27
3

I use Cygwin's versions of the Unix command line tools:

diff -r dir1 dir2

I've also used MinGW in the past. Both have a few gotchas, but are "close enough." For visual diffs, I like WinMerge pretty well.

Michael Brewer-Davis
  • 14,018
  • 5
  • 37
  • 49
1
forfiles /P %folder1Path% /S /C "cmd /c comp /a @path %folder2Path%\@file"

Will work, but I can't remove the prompt question after the first comparison is made.

Martin Tournoij
  • 26,737
  • 24
  • 105
  • 146
Luis Andrés García
  • 5,852
  • 10
  • 43
  • 57
0

Basing on answer of Martin Tournoij I'v written next (and it working well):

del a.txt
forfiles /P %1 /M *.c* /S /C "cmd /c comp /a @path @file /M" >> a.txt
forfiles /P %1 /M *.h /S /C "cmd /c comp /a @path @file /M" >> a.txt
forfiles /P %1 /M *.s /S /C "cmd /c comp /a @path @file /M" >> a.txt

It looks in subdirectories and don't ask any quiestions...

-2

My two directories have the same structure, just a few version changes to the files. Furthermore, my directory was just a folder of python files. So i got away with...

$ cat dir1/*.py > file1.txt 
$ cat dir2/*.py > file2.txt
$ diff file1 file2
Martin Tournoij
  • 26,737
  • 24
  • 105
  • 146
Dylan
  • 49
  • 1
  • 3