Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Option Explicit
- Dim src, dst, f1, f2, mostRecent, objFSO, fso, objStartFolder, objFolder, colFiles, objFile, f, i, objFile1, strCurrentDevices, objFile2, objFile3, strAddress, strNotCurrent, cmd, strFile1, strFile2, arrFile1, arrFile2, intLineCount, strError
- 'Delete files from previous run
- Set objFSO = CreateObject("Scripting.FileSystemObject")
- objStartFolder = "L:InboxTest"
- Set objFolder = objFSO.GetFolder(objStartFolder)
- Set colFiles = objFolder.Files
- For Each objFile in colFiles
- if instr(objFile.Name,".csv") then
- objFSO.DeleteFile "L:InboxTest*.csv"
- end if
- Next
- 'Copy the newest 2 files to the tesing folder
- src = "L:Inbox"
- dst = "L:InboxTest"
- Set fso = CreateObject("Scripting.FileSystemObject")
- mostRecent = Array(Nothing, Nothing)
- For Each f In fso.GetFolder(src).Files
- If LCase(fso.GetExtensionName(f.Name)) = "csv" Then
- If mostRecent(0) Is Nothing Then
- Set mostRecent(0) = f
- ElseIf f.DateLastModified > mostRecent(0).DateLastModified Then
- Set mostRecent(1) = mostRecent(0)
- Set mostRecent(0) = f
- ElseIf mostRecent(1) Is Nothing Or f.DateLastModified > mostRecent(1).DateLastModified Then
- Set mostRecent(1) = f
- End If
- End If
- Next
- For i = 0 To 1
- If Not mostRecent(i) Is Nothing Then mostRecent(i).Copy dst & ""
- Next
- 'Compare the 2 files in L:InboxTest
- strFile1 = mostRecent(0)
- strFile2 = mostRecent(1)
- set objFSO = CreateObject("Scripting.FilesystemObject")
- set objFile1 = objFSO.opentextfile(strFile1,1)
- set objFile2 = objFSO.opentextfile(strFile2,1)
- arrFile1 = split(objFile1.ReadAll,vbNewLine)
- arrFile2 = split(objFile2.ReadAll,vbNewLine)
- objFile1.close
- objFile2.close
- if ubound(arrFile1) < ubound(arrFile2) then
- intLineCount = ubound(arrFile1)
- strError = strFile2 & " is bigger than " & strFile1
- elseif ubound(arrFile1) > ubound(arrFile2) then
- intLineCount = ubound(arrFile2)
- strError = strFile2 & " is bigger than " & strFile1
- else
- intLineCount = ubound(arrFile2)
- end if
- for i = 0 to intLineCount
- if not arrFile1(i) = arrFile2(i) then
- exit for
- end if
- next
- if i < (intLineCount + 1) then
- WScript.Echo "Line " & (i+1) & " not equal"
- ' WScript.Echo strError
- 'MISetErrorCode(1)
- elseif strError <> "" then
- ' WScript.Echo strError
- else
- WScript.Echo "Files are identical."
- 'MISetErrorCode(0)
- end if
Add Comment
Please, Sign In to add comment