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?
tferro999Asked:
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:

http://msdn.microsoft.com/en-us/library/5tx15443%28v=VS.85%29.aspx

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

Set objFSO = CreateObject("Scripting.FileSystemObject")

ProcessFolder(objFSO.GetFolder(strDir1))
Wscript.Quit

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
   Next
   For Each objSubFolder in objFolder.SubFolders
      ProcessFolder(objSubFolder)
   Next
End Function

Open in new window

~bp
0
 
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.

~bp
0
 
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.
0
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.