Comparing two folders in Windows

Have you been in the situation where you have two folders that are almost exactly identical, and you want to know the difference between the two folders? Maybe you want to compare the System32 folder of one computer with that of another, to make sure they both have the same drivers. Checking for differences between folders in Windows is pretty simple, but is a bit hidden from plain view.

For the sake of this tutorial, consider that we FolderA and FolderB, both on the Desktop, and we want to see the difference in the folders’ contents. To do this, we will make use of the Windows Command Processor, which is also known as the Command Prompt.

  1. To open the Command Prompt, hold the Windows key down, and press the ‘R’ key on the keyboard. This will open the Run dialog in Windows.

    From here, type “cmd” and hit Enter. The Command Prompt should open.

    NOTE: If you want to compare files in protected directories, such as the Windows directory, you must run the Command Prompt as “Administrator.” You can do this by right clicking on the Command Prompt item in the Start menu (in Windows Vista, 7, and 8), and choosing “Run as administrator.”

    Now that we have the Command Prompt open, you should see a blinking cursor preceded by the directory the Command Prompt is currently looking at. Unless you ran the Command Prompt as Administrator, you should be in your default user library directory. From here we can get to the Desktop. This article will refer to the Command as simply “cmd” from here on out.

  2. To change the directory to the desktop, type

    cd desktop, and hit Enter.

    ‘cd’ is the cmd’s command for “change directory.” This is how you navigate the folder structures of your storage media using the cmd.

    NOTE: The Windows file system is case insensitive, so typing “cd desktop” is the same as typing “cd Desktop”.

    We are now on the Desktop in the cmd. We can now verify that our folders are here.

  3. We can optionally verify that the folders we want to compare are indeed on the Desktop. To do this, type:

    dir, and hit Enter.

    You should see a listing of the files and folders on the Desktop. If you do indeed have a FolderA and FolderB there, you should seem them listed. For the sake of this tutorial, we will assume that you do.

    Let’s learn how to compare the folders now. The first thing we’ll do is generate a text document for each folder that lists all of its files. We can do this inside the cmd.

  4. To create a text document that lists all of the files of a folder, type:

    dir /b FolderA > FolderAcontents.txt

    We used the dir command in the last step in order to simply list all of the files in the current directory. This time, we are adding a few more options to the dir command. The command “dir FolderA” lists the contents of FolderA, without first changing directory (cd command) to that folder. The command “dir /b” uses the ‘/b’ option which lists the file and folder names, without the additional information such as date, time, and file size. The command “dir > filename” puts the results of running the dir command in a text file, instead of inside the cmd window. We used the ‘/b’ option, the folder name (FolderA), and the redirect to a file syntax, all in the same command.

    NOTE: FolderAcontents.txt did not need to exist prior to running the command. If the indicated file the results are being redirected to does not exist, cmd will create it.

    NOTE: To see other options that the dir command can use, use the command “dir /?”.

    Let’s generate a file that lists FolderB’s contents now.

  5. To create the file that lists FolderB’s contents, type:

    dir /b FolderB > FolderBcontents.txt

    We now have two text files that each list the files within their respective targeted folders: FolderAcontents.txt lists FolderA’s files, and FolderBcontents.txt lists FolderB’s files.

    We’ll now look at how to compare these two text files.

  6. To create a file that summarizes the differences between our two text files, type the command:

    fc FolderAcontents.txt FolderBcontents.txt > Differences.txt

    The “fc” command takes in our two files, and lists the differences between the two files. We used the redirect operator (‘>’) to put the results in a file called Differences.txt.

    If we open Differences.txt, assuming there were in fact differences between FolderAcontents.txt and FolderBcontents.txt, we’ll see a summary of which files exist in FolderA that don’t in FolderB, and vice versa. This is shown by listing all of the parts of the folders where differences lie, and showing all the files that exist in one folder, and the gap where they would be alphabetically in the other folder.

    For example, say FolderA has File1, File2, File3, and File4 and FolderB only has File1, File3, and File4. The Differences.txt file should say something like:

    ***** FolderAcontents.txt
    ***** FolderBcontents.txt

    The Differences.txt file will list, like a sandwich, the two files that each folder shares, and between those two files, all of the files that are different, in alphabetical order.

  7. Hope that helps!

Leave a Reply

Your email address will not be published. Required fields are marked *