How to compare folders in Windows 7
Is there an out of the box way to compare two folders in Windows 7? The comparison should show the differences in terms of subdirectory folders and subdirectory files.
Solution 1:
I'm not a powershell pro, but this would give you which files and folders exist in one folder but not the other.
$test1 = get-childitem -path C:\Users\IrisDaniela\Documents\test1 -recurse
$test2 = get-childitem -path C:\Users\IrisDaniela\Documents\test2 -recurse
compare-object $test2 $test1 | Where {$_.SideIndicator -eq '=>'}
This gives:
InputObject SideIndicator
----------- -------------
test1a =>
test.txt =>
You can also leave out the filtering of course, and get:
$test1 = get-childitem -path C:\Users\IrisDaniela\Documents\test1 -recurse
$test2 = get-childitem -path C:\Users\IrisDaniela\Documents\test2 -recurse
compare-object $test2 $test1
InputObject SideIndicator
----------- -------------
test1a =>
test.txt =>
test2b <=
Dunno if this is what you are looking for, but maybe it gives you a start :)
To compare content use:
compare-object (get-content a.text)(get-content b.txt)
and so on
Solution 2:
There is a good unix tool named diff, which you can install from cygwin. The command diff -urNw /path/to/dir1 /path/to/dir2
likely does what you want.
On win, there is a gui tool named beyondCompare.
Solution 3:
You can make a batch file that creates two temporary text files that contain the directory structure, then compare those temp files with fc
.
Something like (and adjust for preferences):
dir %1 /s /b /a /ong > temp1.txt
dir %2 /s /b /a /ong > temp2.txt
fc temp1.txt temp2.txt
The arguments for the dir command are:
/s
recurse into child folders
/b
don't show details, you could want to omit this maybe
/ong
sort by ascending name, directories first
Also, remember to adjust for possible spaces in the arguments
EDIT: as noted in the comments, we'll have to get rid of the directory prefix from the list-of-files text file. This can be done with a batch file such as:
@echo off
setlocal EnableDelayedExpansion
for /F "delims==" %%a in (%1) do @(
set CURR_LINE=%%a
@echo !CURR_LINE:~%2!
)
endlocal
used as unprefix text_file.txt prefix_length
. So for example unprefix temp1.txt 5
will output the contents of temp1.txt without the first 5 characters of each line.
Solution 4:
I use FreeCommander (a Norton Commander clone) to do this. It provides "Synchronize Folders" feature that allows to compare two folders and optionally synchronize them. The compare options include "By CRC", "By date", "By Content", Sub Folders and mane more. It is very powerful and has helped me many time to perfectly do the very same thing you asked.
Generally, FreeCommander is very powerful tool. the other feature that I use often is search withing files and folders.