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?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Bill PrewIT / Software Engineering ConsultantCommented:
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
Bill PrewIT / Software Engineering ConsultantCommented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
VB Script

From novice to tech pro — start learning today.