Re: Need a script to compare two files
- From: DKS <DKS@xxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Sat, 3 May 2008 22:30:01 -0700
Thanks Tom for your help!
"Tom Lavedas" wrote:
On Apr 29, 5:48 pm, "ekkehard.horner" <ekkehard.hor...@xxxxxxxx>.
wrote:
Tom Lavedas schrieb:
On Apr 29, 4:16 pm, Tom Lavedas <tglba...@xxxxxxx> wrote:
On Apr 29, 3:23 pm, "DKS" <dksa...@xxxxxxxxxxx> wrote:
[...]Hello,
I am looking for a script to compare two files.
Scan second file using the words from first file.
Extract the line that matches the word from second file
Here is how I would do what you asked for ...
'---------------------8<------------------- with corrections
Const ForReading = 1
with CreateObject("Scripting.FileSystemObject")
with .OpenTextFile("C:\Audit\User_Info.txt", ForReading)
arrData = Split(.ReadAll, vbNewline)
Doing such a Split is dangerous because of the (possible) trailing
vbCrLf(s); these generate empty elements in arrData, that will be
'found' by InStr() in every line.
Your point is well taken. I didn't work to make it robust. I think
the addition of an IF Empty type test in the loop below would solve
the problem nicely ...
end with ' Data lines
with .OpenTextFile("C:\Audit\User_First_Name.txt", ForReading)
arrNames = Split(.ReadAll, vbNewline)
end with ' Names
for each data in arrData
if not data = "" Then
for each fname in arrNames
if not fname = "" Then
if InStr(data, trim(fname)) > 0 Then
strOut = strOut & data & vbCrLf
As a name found means that no other name is contained in that line
an "Exit For" would make the script more efficient.
Agreed. It crossed my mind, but I didn't act on it.
End If ' InStr
next ' fname
end if ' fname test
next ' data
end if ' data string test
with .CreateTextFile("C:\Audit\User_New_Info.txt", True)
.Write strOut
end with ' Out file
end with ' FSO
wsh.echo strOut
[...]
Despite my gripe/carping I do like this script very much; thanks
for the inspiring food for thought.
Thanks. I like to keep the code compact, while trying to also balance
its clarity. I find that compact code can be easier to grok when I
come back to it (with a minimum of commenting required) - if I haven't
gotten too cute in squeezing it.
Tom Lavedas
===========
- Follow-Ups:
- Re: Need a script to compare two files
- From: Tom Lavedas
- Re: Need a script to compare two files
- Prev by Date: Re: Are vbscript classes fast?
- Next by Date: Re: MapNetworkDrive not working during first logon
- Previous by thread: Are vbscript classes fast?
- Next by thread: Re: Need a script to compare two files
- Index(es):
Relevant Pages
|