The command: "FC" is on Windows 12, 11, 10, .. , MS Server 2025, 2022, 2019, .. available
The examples for the command "FC"
The
`FC` command in Windows Command Prompt is used to compare the contents of two files. Here are some examples:
Example 1: Simple file comparison:
FC file1.txt file2.txt
Description: Compares the contents of
"File1.txt" and
"File2.txt" and indicates the differences, if any.
Example 2: Comparison with custom separator:
FC /T"," File1.csv File2.csv
Description: Compares the contents of two CSV files (
"File1.csv" and
"File2.csv") using a custom separator (in this case a comma).
Example 3: Binary comparison:
FC /B BinFile1.bin BinFile2.bin
Description: Performs a binary comparison between two binary files (
"BinFile1.bin" and
"BinFile2.bin").
Example 4: Ignoring spaces:
FC /W file1.txt file2.txt
Description: Compares the contents of two text files, ignoring spaces.
Example 5: Displaying hexadecimal differences:
FC /C /L 32 File1.txt File2.txt
Description: Compares the contents of two text files and displays hexadecimal differences. The
`/L` option specifies how many characters to display per line (in this case 32).
Example 6: Displaying Line Numbers:
FC /N File1.txt File2.txt
Description: Compares the contents of two text files and displays the line numbers where differences occur.
Example 7: Batch script with FC and error checking:
@ECHO OFF
FC File1.txt File2.txt > NUL
IF ERRORLEVEL 1 (
ECHO The files are different.
) ELSE (
ECHO The files are identical.
)
Description: Compares the contents of two files and prints an appropriate message based on the exit code of the
`FC` command.
Note: Note that the
`FC` command is suitable for binary comparison, but may not be ideal for comparing large text files or files with different line break formats (e.g., Windows CRLF vs. Unix LF). In such cases, specialized tools such as
`COMP` or third-party tools may be more suitable.
"FC" Excerpt from Microsoft Windows Help
Microsoft Windows [Version 10.0.19045.3693]
(c) Copyright 1985-2023 Microsoft Corp.
C:\\WINDOWS>
Compares two files or sets of files and displays the differences between
them
FC [/A] [/C] [/L] [/LBn] [/N] [/OFF[LINE]] [/T] [/U] [/W] [/nnnn]
[drive1:][path1]filename1 [drive2:][path2]filename2
FC /B [drive1:][path1]filename1 [drive2:][path2]filename2
/A Displays only first and last lines for each set of differences.
/B Performs a binary comparison.
/C Disregards the case of letters.
/L Compares files as ASCII text.
/LBn Sets the maximum consecutive mismatches to the specified
number of lines.
/N Displays the line numbers on an ASCII comparison.
/OFF[LINE] Do not skip files with offline attribute set.
/T Does not expand tabs to spaces.
/U Compare files as UNICODE text files.
/W Compresses white space (tabs and spaces) for comparison.
/nnnn Specifies the number of consecutive lines that must match
after a mismatch.
[drive1:][path1]filename1
Specifies the first file or set of files to compare.
[drive2:][path2]filename2
Specifies the second file or set of files to compare.
Important information, tips for the "FC" command
There are a few important points to note when using the
`FC` command in the Windows Command Prompt:
1.
Differences in file formats: `FC` compares the contents of files, however differences in file formats may result in apparent differences. This is especially true for text files that may use different character encodings or newline characters (e.g., Windows CRLF vs. Unix LF).
2.
Comparison of binary files: The
`FC` command is particularly suitable for binary file comparison, where non-text-based files can also be compared. However, if there are specific requirements for binary comparison (e.g., for version control systems), dedicated tools such as
`COMP` or specialized software may be preferred.
3.
Different file sizes: `FC` returns an error if the compared files are of different sizes. This may be intentional in some cases if you want to ensure that the files are exactly the same size. In other cases, this can lead to false alarms, especially if this is not intended.
4.
Line endings and spaces: By default,
`FC` pays attention to line endings and spaces. Different spaces or line endings can cause
`FC` to report differences, even if the difference in content is minimal. You can use the
`/W` (ignore spaces) and
`/C` (ignore line endings) options to take these aspects into account.
FC /W /C File1.txt File2.txt
5.
Batch script and ERRORLEVEL: If you use
`FC` in a batch script, you can query the exit code with
`ERRORLEVEL` to react to differences. An exit code greater than 0 indicates differences.
FC File1.txt File2.txt > NUL
IF ERRORLEVEL 1 (
ECHO The files are different.
) ELSE (
ECHO The files are identical.
)
6.
Larger files: For very large files, comparing with
`FC` can be resource intensive. In such cases, specialized tools may be able to provide more efficient results.
7.
Syntax and Options: Make sure to use the correct syntax and required options for your specific use case. Using
`/?` displays help for the
`FC` command and gives you information about the available options.
FC /?
Finally, it is important to consider that while
`FC` is suitable for simple comparisons, it may not be the optimal tool for certain scenarios, particularly when there are complex or specialized requirements. In such cases, more advanced tools or scripting languages ??such as PowerShell may be more appropriate.