Login | |
|
 |
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?
|
|
| |
|
|
|
 |
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
|
|
| |
|
|
|
|
|