GeekPolice Tech TutorialsLog in

 

How to Compare the Contents of Two Files Using FC Command

Share

20180219
How to Compare the Contents of Two Files Using FC Command

How to Compare the Contents of Two Files Using FC Command
FC, (File Compare) command, is used to compare two files against each other.

FC.exe is a simple program that will compare the contents of text or binary files and is capable of comparing both ASCII and Unicode text. Once completed, FC returns lines that differ between the two files. If no lines differ, you will receive a message indicating no differences encountered.

First, let's launch the Command Prompt by clicking Start Menu --> All Programs --> Accessories, right-click on Command Prompt, and open it as an administrator. In Windows Vista and later versions of Window operating systems type cmd.exe into Start Screen or Start Menu, right-click on Cmd.exe, and open it as an administrator.

At the Command Prompt, type FC /? command and press Enter key to view the list of FC command parameters.



Wildcards ( * and ? ) may be used with filename1 or filename2, FC will then compare all the matching files.

You will need to know how to enter your commands with the proper syntax.

Code:

 FC [pathname1] [pathname2]


Code:

FC [parameter] [pathname1] [pathname2]


When FC is used for an ASCII comparison, it will display differences between two files in the following order:


  1. Name of the first file
  2. Lines from filename1 that differ between the files
  3. First line to match in both files
  4. Name of the second file
  5. Lines from filename2 that differ
  6. First line to match


Let's compare the contents of two files named “Example.txt” and “Example2.txt”. Remember to substitute the pathname with the name that matches your computer, and remember that command prompt is not case sensitive.

Code:

fc  "E:\My_Notes\Example.txt"  "E:\My_Notes\Example2.txt"




As you can see from the image above, FC reports that no differences were encountered. If you were to edit one file, add a single letter, and try the command again, your results would show up as in the image below. Note that the only thing that was changed was the addition of the letter “a.”



We can tell FC command to stop after 2 lines of mismatched data. Do this, by adding the “/lbn” switch.

Code:

fc  /lb2  "E:\My_Notes\Example.txt"  "E:\My_Notes\Example2.txt"




As you can see, you receive an error message which says “Resync Failed. Files are too different.” This is because there are more than two consecutive lines of mismatched data. Try changing the numbers or editing the files yourself and play with the file compare tool to see what results you get.

Let's make a binary comparison of “Example.txt” and “Example2.txt” files:

Code:

fc /b "E:\My_Notes\Example.txt"  "E:\My_Notes\Example2.txt"




The bunch of binary digits, which is where the files are being compared, side by side, and lastly, you receive a report that says that, Example.txt longer than EXAMPLE2.TXT.














remove_circleSimilar topics

Comments

No Comment.
Permissions in this forum:
You cannot reply to topics in this forum