View Single Post
  #8   Report Post  
Posted to microsoft.public.excel.programming
bruce bruce is offline
external usenet poster
 
Posts: 6
Default Is there a way to create a program in excel to compare files?

This will probably work OK! In order to get around of the 128 char len
difference, I could copy the two files to compare to a "\temp\ subdirectory"
Slower then doing something native, and in its original subdirectory, but it
aleast gives me control of what directories are effected and what order to
delete from!

Thanks
Bruce

"TroyW" wrote in message
...
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" 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