'Compare 2 directories in windows [closed]

I need to compare 2 folders "A" and "B" and get the list of files and folders newly added or modified.

I tried using Winmerge software but it is not comparing the files present inside the internal folders(so i have to point to each internal folder manually and have to compare)

Is there any way to achieve this.



Solution 1:[1]

The following PowerShell code compares the file listings of two folders. It will detect renamed or newly created files and folders, but it will not detect modified data or different timestamps:

$dir1 = Get-ChildItem -Recurse -path C:\dir1
$dir2 = Get-ChildItem -Recurse -path C:\dir2
Compare-Object -ReferenceObject $dir1 -DifferenceObject $dir2

Source: MS Devblog - Dr. Scripto

3rd party edit

How to run a PowerShell script explains how to run the code above in a script.

Solution 2:[2]

For Windows you can use this solution.

Here's the right way to do it, without the external downloads. It looks like a lot at first, but once you've done it, it's very easy.
It works in all Windows versions from 7 back to 95. For our example assume that you're comparing two directories named 'A' and 'B'.

  1. run cmd.exe to get a command prompt. (In Windows 7, the powershell won't work for this, FYI.) Then do it again, so that you have two of them open next to each other.
  2. in each window go to the directories that you want to compare. (Using 'cd' commands. If you're not comfortable with this, then you should probably go with the external utilities, unless you want to learn command prompt stuff.)
  3. type 'dir /b > A.txt' into one window and 'dir /b > B.txt' into the other. You'll now have two text files that list the contents of each directory. The /b flag means bare, which strips the directory listing down to file names only.
  4. move B.txt into the same folder as A.txt.
  5. type 'fc A.txt B.txt'. The command 'fc' means file compare. This will spit out a list of the differences between the two files, with an extra line of text above and below each difference, so you know where they are. For more options on how the output is formatted, type 'fc /?' at the prompt. You can also pipe the differences into another file by using something like 'fc A.txt B.txt > differences.txt'.

Have fun.

Solution 3:[3]

This is not necessarily better than other options already mentioned but it might better fit certain use-cases. In my case, I wanted to see what was different before copying those differences from one directory to the other. This method is great for that since the /L option means to only log what would happen.

robocopy C:\dir1 C:\dir2 /MIR /FP /NDL /NP /L

You can further refine the output format with other flags, or change the logic used to to compare, etc. Refer to robocopy docs for all the options.

Solution 4:[4]

We have been using Beyond Compare for years and it's quite useful. You can see which files are identical, which files are in folder "A" only and which files are in folder "B" only, and files that are different (for those files you can see what specific modifications have been made).

Solution 5:[5]

Some years ago, I made a command line utility, CrcCheckCopy, to help me verify the integrity of large data copies. It reads the source folder and produces a list of the CRCs of all the files. And then, using this list, it can verify the other folder.

I also use it to verify the same folder after some years, to make sure nothing was accidentally deleted or modified.

I give it from free from here in case people who arrive to this question want to try it.

Solution 6:[6]

FreeFileSync did the job for me.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 surfmuggle
Solution 2 gringo_dave
Solution 3
Solution 4 AlfredD
Solution 5 Mike
Solution 6 Sagruob