Re: Is there a way to create a program in excel to compare files?

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance

From: TroyW (nospam_at_yahoo.com)
Date: 06/05/04


Date: Sat, 5 Jun 2004 09:49:38 -0400

Speaking of DOS 1.x. The trusty old FC (filecompare) DOS command is still
available in Windows XP. Below is some basic code to compare two files. A
text output file named FC.TXT will be created with the results of the
binary file comparison.

If the files have any binary differences the output will look something like
this:
Comparing files C:\TEMP\TestFile1.txt and C:\TEMP\TestFile2.txt
0000002A: 33 34

If the files don't have any binary differences the output will look
something like this:
Comparing files C:\TEMP\TestFile1.txt and C:\TEMP\Copy of TestFile1.txt
FC: no differences encountered

You can look for the "FC: no differences encountered" string on line2 of the
output file. Your command line may have a limit on the number of characters
passed (~127).

Troy

Sub TestSomeFiles()
Dim sFile1 As String
Dim sFile2 As String
Dim vFcn As Variant

sFile1 = "c:\temp\TestFile1.txt"
sFile2 = "c:\temp\TestFile2.txt"

vFcn = fcnDOS_FileCompare(sFile1, sFile2)

End Sub

Function fcnDOS_FileCompare(sFile1 As String, sFile2 As String)
Dim sCmd As String
Dim sFC_Filename As String

'Name of the file to direct the output of the DOS FC command to.
sFC_Filename = "c:\temp\FC.TXT"

'--- VBA and Shell are asynchronous, need to wait for FC to finish.
If Dir(sFC_Filename) <> "" Then Kill sFC_Filename
Open sFC_Filename For Random As #1
Close #1

sCmd = "command.com /c FC /B " & _
         """" & sFile1 & """" & " " & _
         """" & sFile2 & """" & " " & _
         "> " & sFC_Filename

Shell sCmd
Do While FileLen(sFC_Filename) = 0
   DoEvents
Loop

'Check for "FC: no differences" in the output file

End Function

The FC command has the following syntax and switches

FC [/Switches] [drive:][\dir\]file1 [drive:][\dir\]file2
Switches:

      /B Performs a binary comparison.
      The two files are compared byte by byte and there is no attempt to
resynchronize the files after finding a mismatch. This is the default mode
for comparing files when file1 has an extension of .EXE, .COM, .SYS, .OBJ,
.LIB, or .BIN.
      /L Compares files as ASCII.
      The two files are compared line by line and FC attempts to
resynchronize the files after finding a mismatch. This is the default mode
for comparing files when file1 does not have an extension of .EXE, .COM,
.SYS, .OBJ, .LIB, or .BIN.
      /LBn Sets the number of lines for the internal line buffer.
      If the files being compared have more than this number of consecutive
differing lines, FC cancels the comparison.
      Default value of n: 100
      /nn The number of consecutive lines that must match before the files
are declared resynchronized. If the number of matching lines in the files is
less than this number, the matching lines are displayed as differences.
      Default value of nn: 2.
      /N Displays the line numbers on an ASCII comparison.
      /A Abbreviates the output of an ASCII comparison. Only the first and
last line for each set of differences is displayed as opposed to the default
of every different line.
      /C Disregards the case of letters.
      /T Does not expand tabs to spaces.
      By default, tabs are treated as spaces with 1 tab = 8 spaces.
      /W Compresses tabs and multiple spaces to a single space for the
comparison.

"bruce" <excel@no-spam.for.me.johnsonclan.net> wrote in message
news:7TSvc.37539$pt3.8849@attbi_s03...
> I have no problem doing a DIR *.jpg /s >templist.txt type of thing. (I
have
> been playing with DOS since DOS 1.x!!!!) I can even import that into
Excel.
> What I then want to do is to do a bit by bit compare on the files that
have
> the same size. This is the part I do not know how to do.
> I could even figure out how not to delete from certain directories (I
think)
> I am not sure if I could also put a preference together for which
> directories would have a "preferred" delete from over a different
> subdirectory
>
> Thanks
>
> Bruce



Relevant Pages

  • Re: Avoiding extra line in Command Line Output
    ... questions about DOS but for versions of BASIC that run in a DOS ... that there are two CR/LF pairs, there are two utilities that may help you. ... The following command will delete *all* ... If the file size is less than 32KB, you could write a string to the end ...
    (microsoft.public.windowsxp.general)
  • Re: Dos Application in Matlab Problem
    ... I am writing a code in Matlab that I would eventually like to compile as a stand alone executable. ... I would like to import a file using uigetfile and use the filename and path stored as inputs into a dos executable. ... When I have complicated command lines like this, ... to string and check that the string is correct before sending it to ...
    (comp.soft-sys.matlab)
  • Re: newbie: I/O with nasm
    ... I want to read a string ... he'll want to learn to take input from either the command ... Working on up the (Linux) stack, the list of command line argument ... obviously way more elegant and simple than in DOS. ...
    (alt.lang.asm)
  • Re: VB6 and Shell
    ... I tried that before and I see the DOS box flash and I check the directory ... >> This is the command I am using it is using other functions. ... >> Private Type STARTUPINFO ... >> lpReserved As String ...
    (microsoft.public.vb.general.discussion)
  • Re: RUN /DETACHED
    ... > This will create an output file that shows the results of your ... > command. ... Your current output is the bit bucket. ... Except that the null string is not a valid ...
    (comp.os.vms)