Abacus Technology
Background
This paper describes the VBScripts I developed to verify the accuracy of file listings in Version Description Documents (VDDs) prior to being used by Server Admins and DBAs on Production deployment nights.
During the early years of the Information Management and Communications Support (IMCS) contract at Kennedy Space Center (KSC), the Mission Assurance QA Group was responsible for ensuring the accuracy of VDDs. One area in the VDD where accuracy was critical, was the listing of the files to be deployed to Production. During the test phase of the software development lifecycle, it was possible that the VDD file listings could get out of sync with the file versions to be deployed. If the Server Admin or DBA discovered that the file listings in the VDD didn’t match the physical files in the staging area, then the release was pulled from the deployment.
Verifying VDD content was a manually intensive and error prone process. The likelihood of not catching errors increased proportionally to the number of files in the deployment list. It was not uncommon to have hundreds of files listed. The tester had to check each file’s date/time stamp and size. In addition, the status of missing or excess files had to be verified from both the VDD to the staging area and from the staging area to the VDD—a very tedious and time consuming task.
The solution took the form of a VBScript which would perform the file comparisons and produce a report that could easily be sent to the development team for resolution.
CheckVDD.vbs
Script Design
Sub ReportFileStatus()
Subroutine which compares the file attributes in the VDD with the file attributes in the staging area and writes the results to a log file.
Sub ProcessFile()
Subroutine which parses out files from the VDD. Calls ReportFileStatus().
Sub ShowFileList(folderspec)
Subroutine which builds an array of filenames from the staging area. Called by ShowFolderList(folderspec)
Function ShowFolderList(folderspec)
A function which traverses the folders in the root directory recursively. Calls ShowFileList(folderspec).
Sub FindMissingVddFiles
Subroutine which compares an array of files from the staging area with an array of files from the VDD and writes the results to a log file.
Sub ReadThrough
Subroutine which reads the text version of the VDD and sets the position in the file at the start of the file listing.
The main script section defines and initializes all variables and constants; prompts the tester for the application’s root directory path; initializes the log file; reads through and processes the input VDD text file; and writes summary information to a log.
'----------------------------------------------------------------------------------
' Script for verifying files listed in a VDD against an Application Staging Area.
'
' File Attributes checked: Date Last Modified and Size
' Count of files in VDD checked against count of files in the specified App
' Staging Area
' Any files missing from the VDD are identified and listed in the Summary
'
' Author: Gerard Sczepura
'
' Description:
' 1. Development runs the following command at the application root directory
' to create the file list for the VDD.
' dir "<app root folder in UNC format>" /s /a-d > <output file>
‘
‘ Example: dir "\\MORBIUS2\Shares\ALT-Common" /s /a-d > d:\vddfiles.txt
'
' 2. The following directories need to be created on the tester's machine:
' D:\vdd\in
' D:\vdd\out
'
' 3. The script prompts the user for the application root directory in UNC
' format.
' The root directory must match the value specified in the dir command from
' step 1.
'
' Example: \\MORBIUS2\Shares\ALT-Common
'
' 4. To create the input file 'D:\vdd\in\filelist.txt' open the VDD in MS Word
' and save as type: Plain Text (*.txt).
'
' 5. The run log is generated in 'D:/vdd/out/results.htm'
'
' Baselined: 5/29/2009
'
' Change History:
' 06/10/2009 Modified main to retrieve app root dir from a .txt file.
' Changed 'Dev Staging' to 'Staging Area' to be
' generic.
'
' 06/24/2009 Added functionality to list files missing from the VDD.
' Fixed a bug to remove extra "\" after root directory.
'
' 07/01/2009 Fixed a bug in the calculation of the iLenRoot variable
' for root dirs containing subdirs, such as
' "Apps\Cisco"
'
' 08/19/2009 Updated messages in the Summary section.
' Added LCase function to string compares in
' FindMissingVddFiles.
' Modified ShowFolderList to list files top-down.
'
' 10/02/2009 Fixed a bug to increase the size of the vddFiles and
' stageFiles arrays from 300 to 1000.
' Redesigned the code which detects application
' subdirectories and improves reliability in handling
' staging areas other than Dev Staging.
'
' 11/19/2009 Reversed the design change made on 10/02/2009 and Modified
' the code which detects subdirectories to allow for
' UNC file specifications instead of drive letters.
' Modified text in the Description section of the comments
' block.
' Made changes to the output file start/end message text.
' Changed the code which acquires the root directory from
' reading a file to retrieving from a dialog box
' prompt.
' Converted results log file to HTML.
‘
' 02/03/2010 Modified the script to allow reading the file list
' directly from a plain text formatted VDD ' '
' instead of requiring the tester to cut-and-paste
' the files list into a .txt file. ' '
' Created new subroutine ReadThrough.
‘
' 12/09/2011 Modified global variable hTab from spaces to to
' support HTML output.
'-----------------------------------------------------------------------------------
Sub ReportFileStatus()
Dim chkFile, DtTm
Dim fso, f
Set fso = CreateObject("Scripting.FileSystemObject")
chkFile = rootDir & subDir & filename
DtTm = ""
If (fso.FileExists(chkFile)) Then
iFound = iFound + 1
vSub = vSub + 1
vddFiles(vSub) = chkFile
Set f = fso.GetFile(chkFile)
DtTm = f.DateLastModified
am_pm = Mid(DtTm, Len(DtTm) -2, 3)
' Trim off the seconds from the file property
DtTm = Mid(DtTm, 1, InStrRev(DtTm, ":") - 1) & am_pm
' Check remaining file attributes
If DtTm = datetime Then
If filesize <> CStr(f.Size) Then
Results.Write "<font color=" & dq & "red" & dq & ">"
Results.Write hTab & subDir & filename & hTab & " Error: " & "File Size Mismatch!"
Results.Write "</font>"
Results.Write "<br>"
Results.Write hTab & hTab & "Expected: " & filesize & hTab & "Found: " & f.Size
Results.Write "<br><br>"
errs = errs + 1
End If
Else
Results.Write "<font color=" & dq & "red" & dq & ">"
Results.Write hTab & subDir & filename & hTab & " Error: " & "Date/Time Mismatch!"
Results.Write "</font>"
Results.Write "<br>"
Results.Write hTab & hTab & "Expected: " & datetime & hTab & "Found: " & DtTm
Results.Write "<br><br>"
errs = errs + 1
End If
Else
Results.Write "<font color=" & dq & "red" & dq & ">"
Results.Write hTab & subDir & filename & hTab & " Error: " & "File Not Found!"
Results.Write "</font>"
Results.Write "<br><br>"
End If
End Sub
Sub ProcessFile()
Dim timespec
' ---------- replace Tabs with spaces
filespec = Replace(filespec, hTab, " ")
filespec = Trim(filespec)
' ---------- get attributes
attrs = Array("","","","")
For i = 0 to 3
attrs(i) = Mid(filespec, 1, InStr(filespec, " ") - 1)
filespec = Mid(filespec, InStr(filespec, " "))
filespec = Trim(filespec)
Next
filename = filespec
datetime = attrs(0)
timespec = attrs(1)
filesize = attrs(3)
' ---------- trim leading zeroes from date & time
If Instr(datetime, "0") = 1 Then
datetime = Mid(datetime, 2)
End If
datetime = Replace(datetime, "/0", "/")
If Instr(timespec, "0") = 1 Then
timespec = Mid(timespec, 2)
End If
am_pm = attrs(2)
datetime = datetime & " " & timespec & " " & am_pm
' ---------- remove commas
filesize = Replace(filesize, ",", "")
ReportFileStatus
End Sub
Sub ShowFileList(folderspec)
Dim fso, f, f1, fc
Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.GetFolder(folderspec)
Set fc = f.Files
For Each f1 in fc
sSub = sSub + 1
stageFiles(sSub) = f1
fileCount = fileCount + 1
Next
End Sub
Function ShowFolderList(folderspec)
Dim fso, f, f1, s, sf
Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.GetFolder(folderspec)
Set sf = f.SubFolders
For Each f1 in sf
folderspec = folderspec & f1.name & "\"
ShowFileList(folderspec)
folderspec = ShowFolderList(folderspec)
' ---------- trim off processed subdirectory
folderspec = Mid(folderspec, 1, Len(folderspec) -1)
folderspec = Mid(folderspec, 1, InstrRev(folderspec, "\"))
Next
ShowFolderList = folderspec
End Function
Sub FindMissingVddFiles
Dim x, y
y = 0
For x = 0 to sSub
If LCase(stageFiles(x)) <> LCase(vddFiles(y)) Then
Results.Write hTab & stageFiles(x) & "<br>"
Else
y = y + 1
End If
Next
End Sub
Sub ReadThrough
Do While vdd_Files.AtEndOfStream <> True
filespec = vdd_Files.ReadLine
filespec = Trim(filespec)
If InStr(1, filespec, "Volume in drive") > 0 Then
Exit Do
End If
Loop
End Sub
' Main _________________________________________
' ---------- Loop and counter variables
Dim iLine, iFiles, iFound, errs, fileCount, iNotFound
Dim i, k
' ---------- File system variables
Dim filePath_in, filePath_out, appDir
Dim fsoIn, fsoOut
' ---------- Miscellaneous variables
Dim bExists
Dim vdd_Files, Results, Root
Dim RootFldr, DriveMapping
Dim filespec, filename, folderspec
Dim filesize, am_pm
Dim rootDir, subDir
Dim datetime
Dim attrs
Dim iLenRoot
' ---------- Constants
Dim msgPrompt, msgPrompt2, msgTitle
Dim hTab, dq
hTab = " "
dq = """"
msgPrompt = "Enter Root Directory in UNC format."
msgPrompt2 = "Example: \\MORBIUS2\Shares\ALT-Common"
msgTitle = "VDD Validation Script"
' ---------- Arrays and subscripts for VDD and Staging files
Dim vddFiles(1000)
Dim stageFiles(1000)
Dim vSub, sSub
filePath_in = "D:\vdd\in\filelist.txt"
filePath_out = "D:\vdd\out\results.htm"
Set fsoIn = CreateObject("Scripting.FileSystemObject")
Set fsoOut = CreateObject("Scripting.FileSystemObject")
' ---------- get the app root directory
Do While k <> 3
RootFldr = InputBox(msgPrompt & vbCrLf & vbCrLf & " " & msgPrompt2, msgTitle)
RootFldr = Trim(RootFldr)
If RootFldr = "" Then
Msgbox("Initiate, the Root Directory must be specified!")
RootFldr = ""
k = k + 1
Else
If fsoIn.FolderExists(RootFldr) Then
Exit Do
Else
Msgbox("Padawan, the Directory must be valid!")
RootFldr = ""
k = k + 1
End If
End If
Loop
iLenRoot = Len(RootFldr)
rootDir = RootFldr
' ---------- get the files
Set vdd_Files = fsoIn.OpenTextFile(filePath_in, 1)
Set Results = fsoOut.OpenTextFile(filePath_out, 2, True)
Results.Write "<html>"
Results.Write "<HEAD>"
Results.Write "<TITLE>VDD Validation Script Results</TITLE>"
Results.Write "</HEAD>"
Results.Write "<body>"
vSub = -1
sSub = -1
iLine = 0
iFound = 0
iFiles = 0
errs = 0
filespec = ""
Results.Write "Comparing VDD to Staging Area on " & Date & " at " & Time
Results.Write "<br><br>"
Results.Write "App Root Directory: " & rootDir
Results.Write "<br><br>"
rootDir = rootDir & "\"
ReadThrough
Do While vdd_Files.AtEndOfStream <> True
filespec = vdd_Files.ReadLine
filespec = Trim(filespec)
If filespec <> "" And InStr(1, filespec, "Volume") = 0 Then
If InStr(1, filespec, "Directory of ") <> 0 Then
If Len(Mid(filespec, 14 + iLenRoot)) > 0 Then ' Len("Directory of ") +1 = 14
subDir = Mid(filespec, 14 + iLenRoot + 1) & "\" ' iLenRoot + 1 to skip "\"
End If
Else
If InStr(1, filespec, "File(s)") = 0 Then
If InStr(1, filespec, "Total Files") <> 0 Then
filespec = vdd_Files.ReadLine
filespec = Trim(filespec)
iFiles = CInt(Mid(filespec, 1, InStr(1, filespec, "F") - 2))
Exit Do
Else
iLine = iLine+1
ProcessFile
End If
End If
End If
End If
Loop
vdd_Files.Close
' ---------- get the count and list of files in Staging Area
fileCount = 0
ShowFileList(rootDir)
ShowFolderList(rootDir)
' ---------- produce the summary and finish
Results.Write "...Compare Completed on " & Date & " at " & Time
Results.Write "<br><br>"
Results.Write "_______________ SUMMARY _________________"
Results.Write "<br><br>"
Results.Write " >>> VDD to Staging Area Results <<<"
Results.Write "<br><br>"
Results.Write "Total Files in VDD = " & iLine & "<br>"
iNotFound = iLine - iFound
Results.Write "Total Files Missing in Staging Area = " & iNotFound & "<br>"
Results.Write "Total Mismatched Files = " & errs
Results.Write "<br><br>"
Results.Write " >>> Staging Area to VDD Results <<<"
Results.Write "<br><br>"
Results.Write "Total Files Expected = " & iFiles & "<br>"
Results.Write "Files Counted in Staging Area = " & fileCount & "<br>"
If iLine < fileCount + iNotFound Then
Results.Write "<br><br>"
Results.Write "<font color=" & dq & "red" & dq & ">"
Results.Write "***** !!ERROR: Files Missing in the VDD!! *****"
Results.Write "</font>"
Results.Write "<br><br>"
FindMissingVddFiles
End If
Results.Write("</body>")
Results.Write("</html>")
Results.Close
Set Up
Create the following directories
mkdir D:\vdd\in mkdir D:\vdd\out
Run the DIR command from a CMD window to create the input text file. The following is used as an example:
dir "\\MORBIUS2\Shares\ALT-Common" /s /a-d > d:\vdd\in\filelist.txt
Running CheckVDD.vbs
- Invoke the CheckVDD.vbs script and when prompted, enter the UNC path of the root directory as shown in the example below:

- If the tester happens to enter a path that doesn’t exist the script displays the following message:

- The file list in the VDD is compared to the Root Directory and the results written to D:\vdd\out\results.htm
Results
The following are the results of our sample run (error text displayed in RED when viewed in a Browser):
App Root Directory: \\MORBIUS2\Shares\ALT-Common
Drivers\VPC-EB290X\Backup\20111225_135016_FileRepository.nba Error: File Size Mismatch!
Expected: 530739411 Found: 530739311
Drivers\VPC-EB290X\Backup\drvlist (2).csv Error: File Not Found!
Hotfix\symbols\dll\mpr.pdb Error: Date/Time Mismatch!
Expected: 3/11/2004 7:37 PM Found: 3/10/2004 7:37 PM
Hotfix\symbols\dll\user32.dbg Error: Date/Time Mismatch!
Expected: 3/23/2004 8:17 PM Found: 3/23/2004 7:17 PM
...Compare Completed on 6/9/2013 at 2:40:50 PM
_______________ SUMMARY _________________
>>> VDD to Staging Area Results <<<
Total Files in VDD = 105
Total Files Missing in Staging Area = 1
Total Mismatched Files = 3
>>> Staging Area to VDD Results <<<
Total Files Expected = 105
Files Counted in Staging Area = 104
Ancillary Scripts
After completing the CheckVDD script I decided to write two follow-on scripts: CopyVDDFiles and FolderCompare. I adapted the algorithms from CheckVDD to create these two other scripts.
CopyVDDFiles prompts for the source folder because in practice, the files may not be copied from the same source folder where the DIR command was run.
The CopyVDDFiles script turned out to be an exercise and was never used to copy files to the Production staging area due to security restrictions in place at the time. Eventually, the Software Services group developed an automated deployment script framework for copying files to the test, development, and production servers.
The FolderCompare script has become obsolete since the commercial application Beyond Compare was acquired.
CopyVDDFiles.vbs
'-----------------------------------------------------------------------------------------
' Script for copying files listed in a VDD to a Production staging area.
'
' Each file copied is listed in the results file indicating source and destination
' locations
' A count of files copied is displayed in the results file
'
' Author: Gerard Sczepura
'
' Description:
' 1. The following directories need to be created on the tester's machine:
' D:\vdd\in
' D:\vdd\out
'
' 2. The script prompts the user for the source and destination folders.
' Example: D:\Source
'
' 3. To create the input file 'D:\vdd\in\filelist.txt' open the VDD in MS Word and
' save as type: Plain Text (*.txt).
'
' 4. The run log is generated in 'D:\vdd\out\fileCopyRes.htm'
'
' Baselined: 12/15/2009
'
' Change History:
' 02/04/2010 Modified the script to allow reading the file list directly
' from a plain text formatted VDD instead of requiring the
' tester to cut-and-paste the files list into a .txt
' file.
' Created new subroutine ReadThrough.
'
' 06/18/2013 Fixed bugs, cleaned up areas of the code, and added additional
' error checking.
'-----------------------------------------------------------------------------------------
Sub ProcessFile()
Set fsoFldr = CreateObject("Scripting.FileSystemObject")
' ---------- replace Tabs with spaces
filespec = Replace(filespec, vbTab, " ")
filespec = Trim(filespec)
' ---------- get filename attribute
filename = filespec
filename = Mid(filename, Instr(filename, "M") + 1)
filename = Trim(filename)
filename = Mid(filename, Instr(filename, " "))
filename = Trim (filename)
' ---------- save filenames and folders
vSub = vSub + 1
vddFiles(vSub) = rootDir & subDir & filename
stageFiles(vSub) = targetFldr & subDir & filename
' ---------- create sub directory
If fsoFldr.FolderExists(targetFldr & subDir) <> true Then
fsoFldr.CreateFolder(targetFldr & subDir)
End If
End Sub
Sub ReadThrough
Do While vdd_Files.AtEndOfStream <> True
filespec = vdd_Files.ReadLine
filespec = Trim(filespec)
If InStr(1, filespec, "Volume in drive") > 0 Then
Exit Do
End If
Loop
End Sub
' Main _________________________________________
' ---------- Loop and counter variables
Dim i, k, vSub
' ---------- File system variables
Dim filePath_in, filePath_out
Dim fsoIn, fsoOut, fsoCpy, fsoFldr
' ---------- Miscellaneous variables
Dim vdd_Files, Results
Dim RootFldr, targetFldr
Dim filespec, filename, folderspec
Dim rootDir, subDir
Dim iLenRoot, iFileCount
' ---------- Constants
Dim msgPrompt, msgPrompt2
Dim msgPrompt3, msgPrompt4
Dim msgTitle
Dim hTab, dq
hTab = " "
dq = """"
msgPrompt = "Enter Source Location in UNC or drive letter format."
msgPrompt2 = "Examples: \\MyServer\Source, D:\Source"
msgPrompt3 = "Enter Destination Location in UNC or drive letter format."
msgPrompt4 = "Examples: \\MyServer\Target, D:\Target"
msgTitle = "VDD File Copy Script"
' ---------- Arrays and subscripts for VDD and Staging files
Dim vddFiles(1000)
Dim stageFiles(1000)
' ---------- initialize the I/O files
filePath_in = "D:\vdd\in\filelist.txt"
filePath_out = "D:\vdd\out\fileCopyRes.htm"
Set fsoIn = CreateObject("Scripting.FileSystemObject")
Set fsoOut = CreateObject("Scripting.FileSystemObject")
Set fsoFldr = CreateObject("Scripting.FileSystemObject")
' ---------- open the I/O files
Set vdd_Files = fsoIn.OpenTextFile(filePath_in, 1)
Set Results = fsoOut.OpenTextFile(filePath_out, 2, True)
' ---------- setup the Results file for HTML
Results.Write "<html>"
Results.Write "<HEAD>"
Results.Write "<TITLE>VDD File Copy Script Results</TITLE>"
Results.Write "</HEAD>"
Results.Write "<body>"
Results.Write "Copying VDD files to Staging Area on " & Date & " at " & Time
Results.Write "<br><br>"
' ---------- get the app root directory
Do While k <> 3
RootFldr = InputBox(msgPrompt & vbCrLf & vbCrLf & " " & msgPrompt2, msgTitle)
RootFldr = Trim(RootFldr)
If RootFldr = "" Then
Msgbox("Initiate, the Root Directory must be specified!")
k = k + 1
Else
If fsoIn.FolderExists(RootFldr) Then
Exit Do
Else
Msgbox("Padawan, the Directory must be valid!")
RootFldr = ""
k = k + 1
End If
End If
Loop
iLenRoot = Len(RootFldr)
rootDir = RootFldr
' ---------- get the target directory
Do While k <> 3
targetFldr = InputBox(msgPrompt3 & vbCrLf & vbCrLf & " " & msgPrompt4, msgTitle)
targetFldr = Trim(targetFldr)
If targetFldr = "" Then
Msgbox("Initiate, the Target Directory must be specified!")
k = k + 1
Else
If fsoFldr.FolderExists(targetFldr) Then
Exit Do
Else
If Msgbox("Do you want to create folder: " & targetFldr & "?") = vbOK Then
fsoFldr.CreateFolder(targetFldr)
Exit Do
Else
Msgbox("Padawan, the Directory must be valid!")
targetFldr = ""
k = k + 1
End If
End If
End If
Loop
vSub = -1
filespec = ""
Results.Write "Source Location: " & rootDir
Results.Write "<br>"
Results.Write "Destination: " & targetFldr
Results.Write "<br><br>"
If InstrRev(rootDir, "\") < Len(rootDir) Then
rootDir = rootDir & "\"
End If
If InstrRev(targetFldr, "\") < Len(targetFldr) Then
targetFldr = targetFldr & "\"
End If
ReadThrough
Do While vdd_Files.AtEndOfStream <> True
filespec = vdd_Files.ReadLine
filespec = Trim(filespec)
If filespec <> "" And InStr(1, filespec, "Volume") = 0 Then
If InStr(1, filespec, "Directory of ") <> 0 Then
If Len(Mid(filespec, 14 + iLenRoot)) > 0 Then ' Len("Directory of ") +1 = 14
subDir = Mid(filespec, 14 + iLenRoot + 1) & "\" ' iLenRoot + 1 to skip "\"
End If
Else
If InStr(1, filespec, "File(s)") = 0 Then
If InStr(1, filespec, "Total Files") <> 0 Then
filespec = vdd_Files.ReadLine
filespec = Trim(filespec)
Exit Do
Else
ProcessFile
End If
End If
End If
End If
Loop
vdd_Files.Close
' ---------- Copy the files
Set fsoCpy = CreateObject("Scripting.FileSystemObject")
iFileCount = 0
For i = 0 to vSub
If fsoCpy.FileExists(vddFiles(i)) <> TRUE Then
Msgbox(vddFiles(i) & " File doesn't exist!")
Else
iFileCount = iFileCount + 1
fsoCpy.CopyFile vddFiles(i), stageFiles(i), true
Results.Write vddFiles(i)
Results.Write "<br>"
Results.Write hTab & "<b>Copied to: </b>" & stageFiles(i)
Results.Write "<br>"
End If
Next
' ---------- produce the summary and finish
Results.Write "<br>"
Results.Write "...Copy Script completed on " & Date & " at " & Time
Results.Write "<br><br>"
Results.Write hTab & iFileCount & "  File(s) copied to Destination"
Results.Write("</body>")
Results.Write("</html>")
Results.Close
Set Up
Create the following directories
mkdir D:\vdd\in mkdir D:\vdd\out
Run the DIR command from a CMD window to create the input text file. The following is used as an example:
dir “D:\Preinstalled" /s /a-d > d:\vdd\in\filelist.txt
Running CopyVDDFiles.vbs
- Invoke the CopyVDDFiles.vbs script
- When prompted, enter the path of the source directory as shown in the example below:

- When prompted, enter the path of the target directory as shown in the example below:

- If the target folder doesn’t exist, the following prompt will be displayed:

- Respond OK to create the target folder
- The files are copied and the results written to D:\vdd\out\fileCopyRes.htm
Results
The following are the results of our sample run (instances of “Copied to:” text displayed in BOLD when viewed in a Browser):
Copying VDD files to Staging Area on 6/18/2013 at 7:33:54 PM
Source Location: D:\Preinstalled
Destination: \\MORBIUS2\Shares\ALT-Common\Target
D:\Preinstalled\autorun.inf
Copied to: \\MORBIUS2\Shares\ALT-Common\Target\autorun.inf
D:\Preinstalled\Quick Reference Guide.pdf
Copied to: \\MORBIUS2\Shares\ALT-Common\Target\Quick Reference Guide.pdf
D:\Preinstalled\Setup.exe
Copied to: \\MORBIUS2\Shares\ALT-Common\Target\Setup.exe
D:\Preinstalled\Three (3) Year Standard Limited Warranty.pdf
Copied to: \\MORBIUS2\Shares\ALT-Common\Target\Three (3) Year Standard Limited Warranty.pdf
D:\Preinstalled\autorun\Canvio3.ico
Copied to: \\MORBIUS2\Shares\ALT-Common\Target\autorun\Canvio3.ico
D:\Preinstalled\autorun\Installer.exe
Copied to: \\MORBIUS2\Shares\ALT-Common\Target\autorun\Installer.exe
D:\Preinstalled\autorun\pref.xml
Copied to: \\MORBIUS2\Shares\ALT-Common\Target\autorun\pref.xml
D:\Preinstalled\Mac Driver\Instruction.pdf
Copied to: \\MORBIUS2\Shares\ALT-Common\Target\Mac Driver\Instruction.pdf
D:\Preinstalled\Mac Driver\Tuxera NTFS for Mac.dmg
Copied to: \\MORBIUS2\Shares\ALT-Common\Target\Mac Driver\Tuxera NTFS for Mac.dmg
D:\Preinstalled\NTI\autorun.new
Copied to: \\MORBIUS2\Shares\ALT-Common\Target\NTI\autorun.new
D:\Preinstalled\NTI\Setup.exe
Copied to: \\MORBIUS2\Shares\ALT-Common\Target\NTI\Setup.exe
D:\Preinstalled\OpenSourceSoftwareInfo\EndUserLicenseAgreement.pdf
Copied to: \\MORBIUS2\Shares\ALT-Common\Target\OpenSourceSoftwareInfo\EndUserLicenseAgreement.pdf
D:\Preinstalled\OpenSourceSoftwareInfo\NTI OpenSourceSoftwareInfo.pdf
Copied to: \\MORBIUS2\Shares\ALT-Common\Target\OpenSourceSoftwareInfo\NTI OpenSourceSoftwareInfo.pdf
D:\Preinstalled\OpenSourceSoftwareInfo\Tuxera OpenSourceSoftwareInfo.pdf
Copied to: \\MORBIUS2\Shares\ALT-Common\Target\OpenSourceSoftwareInfo\Tuxera OpenSourceSoftwareInfo.pdf
...Copy Script completed on 6/18/2013 at 7:40:32 PM
14 File(s) copied to Destination
FolderCompare.vbs
'-----------------------------------------------------------------------------------------
' Script for comparing folder contents, subfolders are scanned recursively.
'
' File Attributes checked: Date Last Modified and Size
'
' The scan runs in two phases. The first phase compares the primary folder to the
' secondary folder.
' The second phase compares the secondary folder to the primary. The script will
' detect missing files in either folder location.
'
' Author: Gerard Sczepura
'
' Description:
' 1. The script prompts the user for the primary and secondary folder locations and
' the results filename.
'
' If the user omits the primary or secondary folder location values, the script will
' display a message dialog. If the user enters the same value for the primary
' and secondary location, the script will display a message dialog.
'
' 2. The run log is generated in the user specified filename.
'
' Baselined: 11/20/2009
'
' Change History:
' 06/20/2013 Fixed bugs.
'
'-----------------------------------------------------------------------------------------
Sub ShowFileList(folderspec, ps)
Dim fso, f, f1, fc
Dim fName
Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.GetFolder(folderspec)
Set fc = f.Files
For Each f1 in fc
Select Case ps
Case "p" vSub = vSub + 1
fName = Replace(LCase(f1.Path), LCase(pLoc), "", 1)
vddFiles(vSub) = fName & " " & f1.DateLastModified & " " & f1.Size
Case "s" sSub = sSub + 1
fName = Replace(LCase(f1.Path), LCase(sLoc), "", 1)
stageFiles(sSub) = fName & " " & f1.DateLastModified & " " & f1.Size
End Select
Next
End Sub
Function ShowFolderList(folderspec, ps)
Dim fso, f, f1, s, sf
Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.GetFolder(folderspec)
Set sf = f.SubFolders
For Each f1 in sf
folderspec = folderspec & f1.name & "\"
ShowFileList folderspec, ps
folderspec = ShowFolderList(folderspec, ps)
' ---------- trim off processed subdirectory
folderspec = Mid(folderspec, 1, Len(folderspec) -1)
folderspec = Mid(folderspec, 1, InstrRev(folderspec, "\"))
Next
ShowFolderList = folderspec
End Function
Sub GetArrayFields(aVal, vType)
Dim aName, adtTime, aTime, aAMPM, afSize
afSize = Mid(aVal, InstrRev(aVal, " ")) 'Get file size
aVal = Mid(aVal, 1, InstrRev(aVal, " ") - 1) 'Trim file size
aAMPM = Mid(aVal, InstrRev(aVal, " ")) 'Get AM/PM
aVal = Mid(aVal, 1, InstrRev(aVal, " ") - 1) 'Trim AM/PM
aTime = Mid(aVal, InstrRev(aVal, " ")) 'Get time
aVal = Mid(aVal, 1, InstrRev(aVal, " ") - 1) 'Trim time
adtTime = Mid(aVal, InstrRev(aVal, " ")) 'Get date
aName = Mid(aVal, 1, InstrRev(aVal, " ") - 1) 'Trim date
Trim(afSize)
adtTime = Trim(adtTime) & aTime & aAMPM
aName = Trim(aName)
Select Case vType
Case "p" fNameX = aName
dtTimeX = adtTime
fSizeX = afSize
Case "s" fNameY = aName
dtTimeY = adtTime
fSizeY = afSize
End Select
End Sub
Sub CompareFolders()
Dim x, y
Dim xVal, yVal
Results.Write "_______________ SUMMARY _________________"
Results.Write "<br><br>"
Results.Write " >>> Phase I: " & pLoc & " to " & sLoc & " Comparison <<<"
Results.Write "<br><br>"
' ---------- Scan Phase I
For x = 0 to vSub
xVal = vddFiles(x)
GetArrayFields xVal, "p"
For y = 0 to sSub
yVal = stageFiles(y)
GetArrayFields yVal, "s"
If LCase(fNameX) = LCase(fNameY) Then
If dtTimeX <> dtTimeY Or fSizeX <> fSizeY Then
Results.Write "<font color=" & dq & "red" & dq & ">"
Results.Write "*** DateTime, FileSize Mismatch: <br>"
Results.Write "</font>"
Results.Write vddFiles(x) & "<br>"
Results.Write stageFiles(y)
Results.Write "<br><br>"
End If
bfound = True
truncFiles(y) = ""
Exit For
End If
Next
If bfound <> True Then
Results.Write "<font color=" & dq & "red" & dq & ">"
Results.Write "*** File: " & fNameX & " not found in Secondary Location - " & sLoc
Results.Write "</font>"
Results.Write "<br><br>"
Else
bfound = False
End If
Next
' ---------- Scan Phase II
Results.Write "<br>"
Results.Write " >>> Phase II: " & sLoc & " to " & pLoc & " Comparison <<<"
Results.Write "<br><br>"
For y = 0 to sSub
yVal = truncFiles(y)
If yVal <> "" Then
GetArrayFields yVal, "s"
For x = 0 to vSub
xVal = vddFiles(x)
GetArrayFields xVal, "p"
If LCase(fNameY) = LCase(fNameX) Then
If dtTimeY <> dtTimeX Or fSizeY <> fSizeX Then
Results.Write "<font color=" & dq & "red" & dq & ">"
Results.Write "DateTime, FileSize Mismatch: <br>"
Results.Write "</font>"
Results.Write stageFiles(y) & "<br>"
Results.Write vddFiles(x)
Results.Write "<br><br>"
End If
bfound = True
Exit For
End If
Next
If bfound <> True Then
Results.Write "<font color=" & dq & "red" & dq & ">"
Results.Write "*** File: " & fNameY & " not found in Primary Location - " & pLoc
Results.Write "</font>"
Results.Write "<br><br>"
Else
bfound = False
End If
End If
Next
Results.Write "<br>"
Results.Write "Compare Completed" & " on " & Date & " at " & Time
End Sub
Set Up
For this example, the script will compare the folders copied using the CopyVDDFiles.vbs script from the previous section. Some errors were introduced for illustration purposes.
Running FolderCompare.vbs
- Invoke the FolderCompare.vbs script
- Respond to the primary folder prompt as follows:

- Respond to the secondary folder prompt as follows:

- Respond to the results file prompt as follows:

- The script compares the two folder locations and writes the results to the specified log file
Results
The following are the results of our sample run (text in error rows are displayed in RED when viewed in a Browser):
Comparing Folders: D:\Preinstalled to \\MORBIUS2\Shares\ALT-Common\Target on 6/22/2013 at 8:21:47 AM _______________ SUMMARY _________________ >>> Phase I: D:\Preinstalled to \\MORBIUS2\Shares\ALT-Common\Target Comparison <<< *** File: \quick reference guide.pdf not found in Secondary Location - \\MORBIUS2\Shares\ALT-Common\Target *** DateTime, FileSize Mismatch: \autorun\pref.xml 1/11/2012 2:57:59 AM 147 \autorun\pref.xml 6/18/2013 8:27:43 PM 147 >>> Phase II: \\MORBIUS2\Shares\ALT-Common\Target to D:\Preinstalled Comparison <<< *** File: \autorun\canvio3.ico not found in Primary Location - D:\Preinstalled Compare Completed on 6/22/2013 at 8:24:09 AM
2013-2026 Gerard Sczepura. All rights reserved.