5

I am manipulating a whole bunch of files and placing them in a different directory. What I need to do now is find out which files are in the original directory that aren't in the output directory (the problem is being processed by a dozen computers). Is there any script I can run on Windows that will display this?

7

Use WinDiff. It comes with Visual Studio and Platform SDK and can be downloaded separately. It's mainly to compare files, but it also allows you to recursively compare folders.

2

In PowerShell:

$d1 = get-childitem -path $dir1 -recurse 
$d2 = get-childitem -path $dir2 -recurse 
compare-object $d1 $d2 
2
  • I did this between a dir on my USB card and my local computer. 10 mins later, still waiting... – jcollum Jun 5 '11 at 17:38
  • Note this method cant see hidden or operating system (eg desktop.ini) files at all, even if you have them displayed in explorer, and will break completely if one of the compare directories are empty for some reason – Hashbrown Apr 10 '19 at 0:35
1

If you are looking for a manual process and have visual studio installed, then you can use windiff.exe to show the differences.

1

I tend to use PathSync

0

you can try this vbscript, no need to download any stuff.

Set objFS = CreateObject("Scripting.FileSystemObject")
Set d = CreateObject("Scripting.Dictionary")
Set objArgs = WScript.Arguments
strFolderA= objArgs(0)
strFolderB = objArgs(1)
Set objFolder = objFS.GetFolder(strFolderA)
Set objFolder1 = objFS.GetFolder(strFolderB)
For Each strFile In objFolder.Files
    strFileName = strFile.Name
    strFilePath = strFile.Path
    'collect all files and their full paths.
    d.Add strFileName, strFilePath
Next

For Each strFile In objFolder1.Files
    strFileName = strFile.Name
    strFilePath = strFile.Path
    If Not d.Exists(strFileName) Then
        WScript.Echo "Not found in : " & strFolderA & "->" & strFilePath
    End If 
Next

output

C:\test>dir /B c:\tmp
file
test.bat

C:\test>dir /B c:\tmp1
test.bat

C:\test>cscript //nologo test.vbs c:\tmp1 c:\tmp
Not found in : c:\tmp1->C:\tmp\file
0

FreeCommander does this quickly. Pick folder on right, pick folder on left, compare. It's a handy utility.

0

In cygwin

comm <options> <(cd $dir1;find -type <type>|sort)  <(cd $dir2;find -type <type>|sort) |less -S

The comm command gives three columns of output unless you suppress them.

I used -S so less doesn't wrap and you can see the columns clearly.

options

  • -23 shows what is unique to $dir1 in first column, suppresses other two columns
  • -13 shows what is unique to $dir2 in second column, suppresses other two columns
  • -12 shows every thing the same between $dir1 and $dir2, suppresses first two columns

type

f for just files d for just directory or use type twice with both or remove type altogether for everything.

In CMD

Note haven't tested the below I assume the pipe works in CMD.

If you got findutils and coreutils from here http://gnuwin32.sourceforge.net/packages.html (because you don't want cygwin) and the less package (but you can use > \somepath\file instead of |less -S then notepad file etc).

cd %dir1%
find -type <type> | sort > \somepath\file1
cd %dir2%
find -type <type> | sort > \somepath\file2
comm <options> file1 file2 |less -S

Note replace $... and #...# with the paths if you don't know how to make variables :)

2
  • It would be nice to have something that compares many directory's and then gives what DIRs have the most in common and what they don't have among the many (of course you could do some bash tricks with the above). Will try WinDiff – sabgenton Jan 21 '13 at 6:51
  • I don't know if it's just me but PS compare-object $d1 $d2 was slow for me. – sabgenton Jan 21 '13 at 6:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.