BrainDump
  Home arrow BrainDump arrow Page 2 - Working with the Filesystem, Drives, Data,...
ASP Free Forums 
.NET  
ASP  
ASP Code  
ASP.NET  
ASP.NET Code  
BrainDump  
C#  
Code Examples  
Database  
Database Code  
IIS  
Microsoft Access  
MS SQL Server  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
ASP Web Hosting  
ASP.NET Web Hosting 
Mobile Linux 
App Generation ROI 
Windows Web Hosting
 
IBM® developerWorks 
Sun Developer Network 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
BRAINDUMP

Working with the Filesystem, Drives, Data, and Search
By: O'Reilly Media
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 1
    2007-07-12

    Table of Contents:
  • Working with the Filesystem, Drives, Data, and Search
  • File Compare (fc)
  • File Expansion Utility
  • File Properties

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Working with the Filesystem, Drives, Data, and Search - File Compare (fc)


    (Page 2 of 4 )

    \windows\system32\fc.exe

    Compare the contents of two files (or sets of files) line by line and display the differences between them.

    To open

    Command Prompt -> fc

    Usage

      fc file1 file2 [/a] [/c] [/lbn] [/n] [/t] [/w] [/offline] [/nnn]
       [/l]
      fc /b filename1 filename2

    Description

    File Compare (fc.exe) compares the contents of two files (or more, using wildcards) and displays the differences (if any). If the files are identical, fc.exe will report FC: no differences encountered. If the files are different, fc.exe lists the differing lines. Here's an example of how to use fc.exe.

    Start with an ordinary text file--say, Bill.txt. Open it in Notepad, change one line, and save it into a new filename--say, Marty.txt. Then open a Command Prompt window, make sure you're in the same directory as the two files, and type the following:

      fc bill.txt marty.txt

    The output will look something like this:

      Comparing files Bill.txt and Marty.txt
      ***** Bill.txt
      Way down Louisiana close to New Orleans
      Way back up in the woods among the evergreens
      There stood a log cabin made of earth and wood
      ***** Marty.txt
      Way down Louisiana close to New Orleans
      Way back up in the woods among the antihistamines
      There stood a log cabin made of earth and wood
      *****

    For each line or sequence of lines that differs in the two files, fc.exe prints out a pair of excerpts from each file. The first and last lines in each excerpt are what the two files have in common and are included for context. The lines in between (only a single line in this example) show the differences. The report will include one pair of excerpts for each difference found; if there are three nonconsecutive differing lines, there will be six excerpts. Here are the options for fc.exe:

    file1, file2

    Specify the filenames of the files to compare. For any files that aren't in the current directory, you'll need to include the full path. If file1  includes a wildcard, all matching files are compared to file2 . Likewise, if file2  includes a wildcard, each matching file is compared to file1 . Both parameters are required.

    /a

    Display only the first and last lines for each set of differences, as opposed to the default of every different line. This option is applicable only if a single sequence of differing lines (resulting in a single excerpt pair) is three lines or longer; otherwise, /a has no effect.

    /c

    Disregard the case of ASCII characters; upper-and lowercase letters are treated as identical.

    /lbn

    Specify the maximum consecutive mismatches; /lb17 will list only the first 17 differing lines. If omitted, the default is 100 maximum mismatches.

    /n

    Include line numbers in the report.

    /t

    Preserve any tabs in the files being compared. By default, tabs are treated as spaces, with one tab equal to eight spaces.

    /w

    Compress whitespace (tabs and spaces) to a single space for comparison. This is possibly useful when comparing .html files, as web browsers will eliminate redundant tabs in spaces as well.

    /offline

    fc.exe normally skips files marked as "offline." Specify /offline (or simply /off) to include offline files as well. (See "Sync Center," in Chapter 7, for more information on offline files.)

    /nnn

    Specify the number of consecutive lines that must match after a mismatch. For example, if you specify /4, a mismatched line followed by three matching lines, followed by one or more mismatched lines, is treated as though it were a single sequence of mismatched lines in the report.

    /l

    Treat the files as ASCII (plain text). Because /l is the default, it has no effect.

    /u

    Treat the files as Unicode text.

    /b

    Treat the files as binary and perform the comparison on a byte-by-byte basis (similar to comp.exe, the other file comparison utility). Differing bytes are displayed in parallel columns, instead of in the pairs of excerpts explained earlier. A binary comparison is typically appropriate only for files of the same sizes, but unlike comp.exe, the comparison will still be performed if they are different sizes. You can't use the /b option in conjunction with any of the other options.

    Notes

    • Windows Vista actually comes with two file comparison utilities: comp.exe (discussed in the preceding section) and fc.exe (this one). comp.exe performs a character-by-character comparison, but displays differences only if the files are exactly the same size. fc.exe performs a line-by-line comparison and works regardless of the file sizes. For most users, fc.exe will be the tool of choice, as it displays the differences between the files and doesn't have any prompts, so you can use it from a WSH script or batch file.
    • fc.exe is most useful when comparing two different but similar text files. For example, you can compare two Registry patches (because .reg files are plain-text files) made at two different times to see what changes have been made. See Chapter 13 for more information on Registry patches.
    • Although fc.exe can compare two binary files, if you try to compare two word processor documents (.doc and .wpd files are binary files), the results won't be terribly helpful. Try converting the documents to an ASCII-based format, such as .rtf or .html, and then perform an ASCII comparison. Naturally, most modern word processors have their own document comparison tools, but they can often be limited; although word processors may miss subtle formatting changes, fc.exe will catch every single difference.
    • If you just want to see whether two files are different, you can redirect the differences to the nul: device and use the fact that fc.exe sets an ERRORLEVEL of 1 when the files differ:

        fc file1 file2 > nul:
      if ERRORLEVEL 1 (echo Different) ELSE (echo Same)


      This will also let you compare two binary files without your command prompt beeping at you while you press Ctrl-C in a desperate attempt to halt the stream of non-ASCII characters flooding your screen.

    More BrainDump Articles
    More By O'Reilly Media


       · This article is an excerpt from the book "Windows Vista in a Nutshell," published by...
     

    Buy this book now. This article is excerpted from chapter four of the book Windows Vista in a Nutshell, written by Preston Gralla (O'Reilly, 2006; ISBN: 0596527071). Check it out today at your favorite bookstore. Buy this book now.

    BRAINDUMP ARTICLES

    - Nilpo`s Top Windows Add-Ons
    - Beginning Silverlight 2.0 Development using ...
    - Fixing Vista`s Troubles
    - Preparing Windows Images for Mass Deployment
    - The Trouble With Vista
    - Slipstreamed and Unattended Windows Installa...
    - Microsoft Office SharePoint Server
    - Microsoft Office SharePoint Designer
    - Microsoft Windows SharePoint Services 3.0
    - Microsoft Live Mesh Overview
    - XAML Brushes and Silverlight
    - Silverlight and XAML Basics
    - Immortal XP
    - XAML Basics
    - Microsoft Surface





    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway
    Stay green...Green IT