VBscript help

I'm a VBscript newbie in need of help.

I need a script that will recursively search through two directories and export a list of the files with their modified dates and archive bits into two different csv files.  I then need to compare the two lists of files.  For all files with matching modified dates but different archive bits, I want to set the archive so they are synchronized.

I don't expect anyone to write this for me, hopefully I can learn something here, but can anyone provide some code snippets for any of the steps I outlined above?
Who is Participating?
Bill PrewCommented:
Here's something to get you started.  You'll need to read up a little on attribute handling, and setting, see the following link:


Const strDir1 = "X:\EE\EE26920551\Dir1"
Const strDir2 = "X:\EE\EE26920551\Dir2"

Set objFSO = CreateObject("Scripting.FileSystemObject")


Function ProcessFolder(objFolder)
   For Each objFile In objFolder.Files
      strDir2Path = Replace(objFile.Path, strDir1, strDir2, 1, -1, vbTextCompare)
      If objFSO.FileExists(strDir2Path) Then
         Set objFile2 = objFSO.GetFile(strDir2Path) 
         If objFile.DateLastModified = objFile2.DateLastModified Then
            If objFile.Attributes <> objFile2.Attributes Then
               Wscript.Echo "Difference Found:"
               Wscript.Echo "  File1: " & Chr(34) & objFile.Path & Chr(34) & "," & FormatDateTime(objFile.DateLastModified, vbShortDate) & "," & objFile.Attributes
               Wscript.Echo "  File2: " & Chr(34) & objFile2.Path & Chr(34) & "," & FormatDateTime(objFile2.DateLastModified, vbShortDate) & "," & objFile2.Attributes
            End If
         End If
         Set objFile2 = Nothing
      End If
   For Each objSubFolder in objFolder.SubFolders
End Function

Open in new window

Bill PrewCommented:
So, is the directory structure of the two top level directories to be compared the same, and do the files need to be in the same subfolder tree to be a match?  Once I understand this I can provide some samples.

Also, why export at all, why not just read all the files in the first directory, and for each file look for a match in the other directory.  Then if the file exists, do your compare of date and attributes and correct as desired.

tferro999Author Commented:
The directory structure should be the same, and they should be in the same subfolder tree to be a match.

I will be comparing a directory, lets say T:\backups with a snapshot of that same volume which would be mounted as S:\backups.

I guess I don't need to export the two lists of files.  I would like to have a single file after comparing the date and attributes as a log file of what changes were made to the archive bit.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.