Photo Gallery Member List Search Calendars FAQ Ticket List Log Out


VBscript comparing files.. Really need some help

 
Logged in as: Guest
arrSession:exec spGetSession 2,2,1286
 Active Users: There are 0 members and 0 guests.
 Users viewing this topic: none
 

 

 
  
  Printable Version
All Forums >> [Scripting] >> WSH & Client Side VBScript >> VBscript comparing files.. Really need some help
  Do you like VisualBasicScript.com? Link to us and help spread the word about our forum. Thanks!
Page: [1]
Login
Message << Older Topic   Newer Topic >>
 VBscript comparing files.. Really need some help - 8/24/2004 9:16:16 PM   
  Wimmo

 

Posts: 4
Score: 0
Joined: 8/24/2004
From: Netherlands
Status: offline
HI,

I need a script that compares some files.

I have an application that writes some xml files to a server, when the app succeeds in that it writes a *chk file with the same name as the *.xml file like
test1.xml,
test1.chk.

If these two files are there the communication from the app to the server is completed, if there is only the xml file it means communication was interrupted,

I need a script that checks all the xmlfiles in that directory has a chk file if not delete the xmlfiles without chk file and move the xml files with chkfiles to another directory.

Can someone help me, I am not so good in vbscript[xx(].

Cheers Wim
 
 
Post #: 1
 
 Re: VBscript comparing files.. Really need some help - 8/25/2004 12:12:16 AM   
  mbouchard


Posts: 1916
Score: 16
Joined: 5/15/2003
From: USA
Status: offline
There might be a better way to do this but this is something I found after a bit of searching.


      

(in reply to Wimmo)
 
 
Post #: 2
 
 Re: VBscript comparing files.. Really need some help - 8/25/2004 7:49:49 PM   
  Wimmo

 

Posts: 4
Score: 0
Joined: 8/24/2004
From: Netherlands
Status: offline
Thanx for your response,
I tried it and it's not complete clear for me!
So i think this checks if every xml file (i changed vbs into xml)has a check file,
but where can i say what to do with it.
It has to delete the xml files without a chk file and move the xml with chk files into another folder.

Cheers Wim

(in reply to Wimmo)
 
 
Post #: 3
 
 Re: VBscript comparing files.. Really need some help - 8/25/2004 11:47:24 PM   
  mbouchard


Posts: 1916
Score: 16
Joined: 5/15/2003
From: USA
Status: offline
Let me think on that. One question. Will there ever be a chk file with no corresponding xml file?

(in reply to Wimmo)
 
 
Post #: 4
 
 Re: VBscript comparing files.. Really need some help - 8/26/2004 12:16:41 AM   
  mbouchard


Posts: 1916
Score: 16
Joined: 5/15/2003
From: USA
Status: offline
Was quicker that I thought it would be.

I have updated the script that I posted earlier, adding some code to delete the files and move the rest. Also moved the getbasename.

quote:
Dim Fso, MyArray1, MyArray2
Dim oDict
Dim aLinesToKeep()
Dim i, j

Set Fso = CreateObject("Scripting.FileSystemObject")

Set f = fso.GetFolder("c:\nt\custom")
Set fc = f.Files
For Each f1 in fc
If Right(f1.name, 4) = ".chk" Then
' s1 = s1 & fso.GetBaseName(f1.name) & ","
s1 = s1 & f1.name & ","
Elseif Right(f1.name,4) = ".vbs" then
s2 = s2 & f1.name & ","
End If
Next
MyArray1 = Split(s1 ,",")
MyArray2 = Split(s2,",")

On Error Resume Next ''file1 may have its own duplicates, but that's fine
Set oDict = CreateObject("Scripting.Dictionary")
For i = 0 To UBound(MyArray1)
oDict.Add fso.GetBaseName(MyArray1(i)), MyArray1(i)
Next

For i = 0 To UBound(MyArray2)
oDict.Add fso.GetBaseName(MyArray2(i)), MyArray2(i)
If Err.Number = 0 Then
j = UBound(aLinesToKeep) + 1
Redim Preserve aLinesToKeep(j)
aLinesToKeep(j) = MyArray2(i)
'Deletes XML files with no CHK file.
'Perform any logging of deleted files here.
Fso.DeleteFile("c:\nt\custom\" & MyArray2(i))
End If
Err.Clear

Next
On Error Goto 0

'Move all files from the folder.
Set fc = f.Files
For Each f1 in fc
fso.MoveFile f1.Path, "c:\nt\custom\new folder\"
Next


(in reply to Wimmo)
 
 
Post #: 5
 
 Re: VBscript comparing files.. Really need some help - 8/30/2004 10:07:26 PM   
  Wimmo

 

Posts: 4
Score: 0
Joined: 8/24/2004
From: Netherlands
Status: offline
quote:
Originally posted by mbouchard

Let me think on that. One question. Will there ever be a chk file with no corresponding xml file?



No it is not possible.

(in reply to Wimmo)
 
 
Post #: 6
 
 Re: VBscript comparing files.. Really need some help - 8/30/2004 10:09:52 PM   
  Wimmo

 

Posts: 4
Score: 0
Joined: 8/24/2004
From: Netherlands
Status: offline
It works perfect, i cannot thank you enough for your time and efforts!
Is there a place where i can vote for you or is there something else i can do for you? Plz let me know.


Kind regards Wim

(in reply to Wimmo)
 
 
Post #: 7
 
 
 
  

If you found our site useful please link to us <a href="http://www.visualbasicscript.com">VisualBasicScript.com</a>.
All Forums >> [Scripting] >> WSH & Client Side VBScript >> VBscript comparing files.. Really need some help Page: [1]
Jump to:





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts