How do I compare two directories on cmd prompt of Windows m/c? I want equivalent of diff -r of UNIX.
-
2Probably belongs on ServerFault instead. – Artem Russakovskii Jun 18 '09 at 07:38
-
15Not really, I think. Comparing files is a common operation for programmers too. – Joey Jun 18 '09 at 07:40
9 Answers
Install Cygwin and you can use diff -r
on Windows.

- 479,566
- 201
- 878
- 984

- 272,464
- 47
- 358
- 399
The comp command for Windows is what you're looking for.
Here the example:
To compare the contents of the directory C:\Reports with the backup directory \\Sales\Backup\April, type:
comp c:\reports \\sales\backup\april

- 35,514
- 12
- 68
- 79
-
3Note that Windows' `comp` is nothing like `diff`. Comp only tells you of the position of differing bits in the file, but does not perform an entire line-by-line comparison of files. There is a `/a` switch for getting s character-by-character comparison, but again it only gives you the single first differing character on a line. I was recommended to use [Compare and Merge](http://compareandmerge.com/buynow.html) but at $40 it is steep. Another poster mentioned GNU diff for Windows but I cannot get it to run on Windows XP SP3 due to some missing DLL. Note that I was using the provided binaries. – dotancohen Apr 15 '12 at 01:26
-
6:/ It seems to me that `comp` isn't really recursive? I tried: `mkdir foo1\bar\baz foo2\bar\baz & echo x > foo1\bar\baz\boo & echo y > foo2\bar\baz\boo & comp foo1 foo2`, and only got some dumb error: `Can't find/open file: foo1\*.*` – akavel Dec 17 '14 at 10:38
The easiest way would probably be downloading diff for Windows: http://gnuwin32.sourceforge.net/packages/diffutils.htm
You could also do something like:
dir directory1 > dir1
dir directory2 > dir2
comp dir1 dir2
Also, some versions of Windows comes with windiff
, however that is a GUI tool

- 12,203
- 5
- 48
- 82
In Windows there is the fc
command. I think diff
is way better, but if you want to use only what came with the installation, well, here you go! :)

- 2,909
- 5
- 36
- 63
-
This question calls for a recursive solution. Currently "fc" does not recurse. – H2ONaCl Jan 21 '18 at 02:55
You can use windiff util included in Windows from NT version and up. Just run 'windiff' and a graphic tool will pop up.
File -> Compare directories
http://msdn.microsoft.com/en-us/library/aa266122(VS.60).aspx
This article describes how to use it from command line. Great benefit of this tool is that it is already included and you don't need to download and install anything.

- 17,696
- 11
- 76
- 110

- 758
- 1
- 7
- 14
-
windiff is not installed in the Windows XP SP3 Professional machine that I am being forced to use. The documentation hints but does not mention explicitely that windiff is installed along with Visual Studio. I use VIM and won't install VS. – dotancohen Apr 15 '12 at 01:56
To compare data with command prompt you can use
COMP /a /l D:\Folder1\data.txt D:\Folder2\data.txt
There can be different options like specific numbers of lines to search and case insensitive search and even you can compare folders with command prompt. Here are other options to compare files and folders with command prompt.

- 1
- 1
-
This question requires a recursive solution. Currently "comp" does not recurse. – H2ONaCl Jan 21 '18 at 02:56
Partial solution with ROBOCOPY
A partial solution (and thus for me unfortunately a "non-solution", although I had high hopes for it initially), which may or may not be enough for you:
It seems the ROBOCOPY tool can be (ab-)used to work as a kinda poor man's recursive comparison; with the unfortunate limitation, that it apparently doesn't compare file contents. It seems to compare sizes, dates and optionally attributes. The magic incantation for this would be:
ROBOCOPY path1 path2 /e /l /ns /njs /njh /ndl /fp /log:result.txt /it
where options meaning seems to be:
/e
- recurse, including empty directories;/l
- only print a log, don't modify files;/ns /njs /njh
- don't print file sizes, job summary, job header;/ndl
- "don't log folder names"- NOTE: this reportedly will result in skipping cases of missing/superfluous empty dirs; if you don't use this, those should get logged, but you'll have to somehow remove non-differing dirs by other means;
/log:result.txt
- write results to 'result.txt' file; I think this can be omitted and result will be shown on standard output then.
Additional options:
/it
- I think this should be added if you want to compare attributes too - see an explanation on what "tweaked" files are.
Warning: does NOT compare file contents
As I said above, this seems not to compare file contents, unfortunately. I verified this by running the following command first:
mkdir d1\a\b d2\a\b & echo x > d1\a\b\f & echo y > d2\a\b\f
Most of the time, this should produce files d1\a\b\f and d2\a\b\f with same timestamps, you can verify with dir d1\a\b\f d2\a\b\f
. The robocopy
call on d1 & d2 produced an empty result set for me.