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

B

bruce

I am trying to clean up my drives and am looking for a way to compare and
delete by my specifications. All of the programs I have used, either lump
all files and compare by name only, for do not have the inteligence to allow
me to select the order of dirctories to delete from. I would also like it
to leave certain subdirectories alone, but use them to compare to other
files.
Would this God awful slow?


I hope I am making this clear enough...

Thanks
 
D

David

Not certain I completely understand what you are trying
to do, but you can write your directories to a file from
DOS, Dir > tofilelist. Been a while since I have done
this and I only got the immediate directory list. Maybe
someone can remeber how to get the drive. Once you get
it, you can open in Excel. Think if you have to you can
append to the to the "tofilelist" file.
 
B

bruce

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
 
A

AA2e72E

If you have WORD and your files are text files, create two documents in respect of each file: he first contains the 'source' and the second the 'target'

Open either the 'source' or the 'target' in WORD and then use : Tools | Track Changes |Compare Documents. This will alter the document you have open (so don't save it or you'll overwrite the original). The active document has vertical bars in the left margin wherever there are differences. Text which has been struck through indicates text that has been removed; text that is underlined shows new text. The comparison is text sensitive.
 
B

bruce

I have not found any CRC checkers that will allow me to control the deleted
files well enough (from certain subdirectories not to delete files from but
still use the files to compare against) or controlling which subdirectories
have the preferred deletion.

I am looking at ExamDiffPro now, but from what I see, it does not do it
either.

The best I have seen so far is "CloneMaster" If it just had a option to the
directory controls, it would be great!

All I need to know is how to read a binary file (which should not be to big
of a deal) and then how to compare. Since we ARE talking BINARY files, I am
NOT sure how to do this in Excel.....
The rest, I know how to do. Excel is the method I would use as I am more
familiar with it than any other langage, and it would allow me to sort the
directories and other manipulations

Thanks

Bruce
 
T

TroyW

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.
 
B

bruce

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 said:
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 said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top