Guest User

Untitled

a guest
Feb 23rd, 2018
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.27 KB | None | 0 0
  1. Option Explicit
  2.  
  3. 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
  4.  
  5. 'Delete files from previous run
  6. Set objFSO = CreateObject("Scripting.FileSystemObject")
  7. objStartFolder = "L:InboxTest"
  8.  
  9. Set objFolder = objFSO.GetFolder(objStartFolder)
  10.  
  11. Set colFiles = objFolder.Files
  12. For Each objFile in colFiles
  13. if instr(objFile.Name,".csv") then
  14. objFSO.DeleteFile "L:InboxTest*.csv"
  15. end if
  16. Next
  17.  
  18.  
  19. 'Copy the newest 2 files to the tesing folder
  20. src = "L:Inbox"
  21. dst = "L:InboxTest"
  22.  
  23. Set fso = CreateObject("Scripting.FileSystemObject")
  24.  
  25. mostRecent = Array(Nothing, Nothing)
  26.  
  27. For Each f In fso.GetFolder(src).Files
  28. If LCase(fso.GetExtensionName(f.Name)) = "csv" Then
  29. If mostRecent(0) Is Nothing Then
  30. Set mostRecent(0) = f
  31. ElseIf f.DateLastModified > mostRecent(0).DateLastModified Then
  32. Set mostRecent(1) = mostRecent(0)
  33. Set mostRecent(0) = f
  34. ElseIf mostRecent(1) Is Nothing Or f.DateLastModified > mostRecent(1).DateLastModified Then
  35. Set mostRecent(1) = f
  36. End If
  37. End If
  38. Next
  39.  
  40. For i = 0 To 1
  41. If Not mostRecent(i) Is Nothing Then mostRecent(i).Copy dst & ""
  42. Next
  43.  
  44. 'Compare the 2 files in L:InboxTest
  45.  
  46. strFile1 = mostRecent(0)
  47. strFile2 = mostRecent(1)
  48. set objFSO = CreateObject("Scripting.FilesystemObject")
  49. set objFile1 = objFSO.opentextfile(strFile1,1)
  50. set objFile2 = objFSO.opentextfile(strFile2,1)
  51. arrFile1 = split(objFile1.ReadAll,vbNewLine)
  52. arrFile2 = split(objFile2.ReadAll,vbNewLine)
  53. objFile1.close
  54. objFile2.close
  55.  
  56. if ubound(arrFile1) < ubound(arrFile2) then
  57. intLineCount = ubound(arrFile1)
  58. strError = strFile2 & " is bigger than " & strFile1
  59. elseif ubound(arrFile1) > ubound(arrFile2) then
  60. intLineCount = ubound(arrFile2)
  61. strError = strFile2 & " is bigger than " & strFile1
  62. else
  63. intLineCount = ubound(arrFile2)
  64. end if
  65.  
  66. for i = 0 to intLineCount
  67. if not arrFile1(i) = arrFile2(i) then
  68. exit for
  69. end if
  70. next
  71.  
  72. if i < (intLineCount + 1) then
  73. WScript.Echo "Line " & (i+1) & " not equal"
  74. ' WScript.Echo strError
  75. 'MISetErrorCode(1)
  76. elseif strError <> "" then
  77. ' WScript.Echo strError
  78. else
  79. WScript.Echo "Files are identical."
  80. 'MISetErrorCode(0)
  81. end if
Add Comment
Please, Sign In to add comment