VBScript help required - How do I check a second path

I need a little help with this script.  The logic is working as I want it to, but I need to be able to have it check two different SubFolder paths on the same server.  I'm guessing this can be done in a single script, it's just that I am not sure how. The script is attached.

BTW - the script simply checks the subfolders modified date against the current date.

I hope I'm explaining myself clearly. If not please ask questions.

Thanks in advance.

SK
'Dim Path1, Path2  - Not sure this is correct way to do what I want

Const ForWriting = 2

Outputfile = "C:\TEST\Result.csv" 'Output results to csv

strComputer = "SERVERN002"

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set Output = objfso.CreateTextFile(Outputfile, ForWriting, True)

Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")

strFolderName = "C:\FOLDER\INFO-1"  'Currently works to check the subfolders, but it is only one folder I need to check
'Path1 = "C:\FOLDER\INFO-1"    
'Path2 = "C:\FOLDER\INFO-2"   'I also want to check the subfolders of this folder

Output.WriteLine

Set colSubfolders = objWMIService.ExecQuery _
    ("Associators of {Win32_Directory.Name='" & strFolderName & "'} " _
        & "Where AssocClass = Win32_Subdirectory " _
            & "ResultRole = PartComponent")

For Each objFolder in colSubfolders
    GetSubFolders strFolderName
Next

Sub GetSubFolders(strFolderName)
    Set colSubfolders = objWMIService.ExecQuery _
        ("Associators of {Win32_Directory.Name='" & strFolderName & "'} " _
            & "Where AssocClass = Win32_Subdirectory " _
                & "ResultRole = PartComponent")

    For Each objFolder in colSubfolders
        strFolderName = objFolder.Name
        dtLastModified = WMIDateStringToDate(objFolder.LastModified)
    If Day(Now)&Month(Now)&Year(Now) = Day(dtLastModified)&Month(dtLastModified)&Year(dtLastModified) Then
        Output.WriteLine objFolder.Name
        Output.WriteLine "Last modified: " & dtLastModified & " **** Successful ****"
        Output.WriteLine ""
    Else
      Output.WriteLine objFolder.Name
      Output.WriteLine " FAILED - Check the Scripts on the FAILED Server"
      Output.WriteLine ""
    End If
      GetSubFolders strFolderName
    Next
End Sub

Output.Close

'**** The Code above is accurate **********

Function WMIDateStringToDate(sLastModified)
    WMIDateStringToDate = CDate(Mid(sLastModified, 7, 2) & "/" & _
    Mid(sLastModified, 5, 2) & "/" & Left(sLastModified, 4) _
    & " " & Mid (sLastModified, 9, 2) & ":" & _
    Mid(sLastModified, 11, 2) & ":" & Mid(sLastModified, 13, 2))
End Function

Open in new window

CompareFolderDate.txt
lasthopeAsked:
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.

KimputerCommented:
Assuming I interpret your request correctly and you want exactly the same operation, except on another folder, here's the code. Path1 and Path2 vars not used. Only useful if you need even more iterations.
Const ForWriting = 2

Outputfile = "C:\TEST\Result.csv" 'Output results to csv

strComputer = "SERVERN002"

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set Output = objfso.CreateTextFile(Outputfile, ForWriting, True)

Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")

strFolderName = "C:\FOLDER\INFO-1"  'Currently works to check the subfolders, but it is only one folder I need to check

Output.WriteLine

Set colSubfolders = objWMIService.ExecQuery _
    ("Associators of {Win32_Directory.Name='" & strFolderName & "'} " _
        & "Where AssocClass = Win32_Subdirectory " _
            & "ResultRole = PartComponent")

For Each objFolder in colSubfolders
    GetSubFolders strFolderName
Next

'extra code starts here

strFolderName = "C:\FOLDER\INFO-2" 

Set colSubfolders = objWMIService.ExecQuery _
    ("Associators of {Win32_Directory.Name='" & strFolderName & "'} " _
        & "Where AssocClass = Win32_Subdirectory " _
            & "ResultRole = PartComponent")

For Each objFolder in colSubfolders
    GetSubFolders strFolderName
Next

'extra code ends here


Sub GetSubFolders(strFolderName)
    Set colSubfolders = objWMIService.ExecQuery _
        ("Associators of {Win32_Directory.Name='" & strFolderName & "'} " _
            & "Where AssocClass = Win32_Subdirectory " _
                & "ResultRole = PartComponent")

    For Each objFolder in colSubfolders
        strFolderName = objFolder.Name
        dtLastModified = WMIDateStringToDate(objFolder.LastModified)
    If Day(Now)&Month(Now)&Year(Now) = Day(dtLastModified)&Month(dtLastModified)&Year(dtLastModified) Then
        Output.WriteLine objFolder.Name
        Output.WriteLine "Last modified: " & dtLastModified & " **** Successful ****"
        Output.WriteLine ""
    Else
    	Output.WriteLine objFolder.Name
    	Output.WriteLine " FAILED - Check the Scripts on the FAILED Server"
    	Output.WriteLine ""
    End If
    	GetSubFolders strFolderName
    Next
End Sub

Output.Close

'**** The Code above is accurate **********

Function WMIDateStringToDate(sLastModified)
    WMIDateStringToDate = CDate(Mid(sLastModified, 7, 2) & "/" & _
    Mid(sLastModified, 5, 2) & "/" & Left(sLastModified, 4) _
    & " " & Mid (sLastModified, 9, 2) & ":" & _
    Mid(sLastModified, 11, 2) & ":" & Mid(sLastModified, 13, 2))
End Function

Open in new window

0
RobSampsonCommented:
You can also use an array and just loop through the folder paths.

Regards,

Rob.

'Dim Path1, Path2  - Not sure this is correct way to do what I want

Const ForWriting = 2

Outputfile = "C:\TEST\Result.csv" 'Output results to csv

strComputer = "SERVERN002"

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set Output = objfso.CreateTextFile(Outputfile, ForWriting, True)

Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")

arrFolders = Array("C:\FOLDER\INFO-1", "C:\FOLDER\INFO-2")

For Each strFolderName In arrFolders
	Output.WriteLine
	
	Set colSubfolders = objWMIService.ExecQuery _
	    ("Associators of {Win32_Directory.Name='" & strFolderName & "'} " _
	        & "Where AssocClass = Win32_Subdirectory " _
	            & "ResultRole = PartComponent")
	
	For Each objFolder in colSubfolders
	    GetSubFolders strFolderName
	Next
Next

Output.Close

Sub GetSubFolders(strFolderName)
    Set colSubfolders = objWMIService.ExecQuery _
        ("Associators of {Win32_Directory.Name='" & strFolderName & "'} " _
            & "Where AssocClass = Win32_Subdirectory " _
                & "ResultRole = PartComponent")

    For Each objFolder in colSubfolders
        strFolderName = objFolder.Name
        dtLastModified = WMIDateStringToDate(objFolder.LastModified)
    If Day(Now)&Month(Now)&Year(Now) = Day(dtLastModified)&Month(dtLastModified)&Year(dtLastModified) Then
        Output.WriteLine objFolder.Name
        Output.WriteLine "Last modified: " & dtLastModified & " **** Successful ****"
        Output.WriteLine ""
    Else
      Output.WriteLine objFolder.Name
      Output.WriteLine " FAILED - Check the Scripts on the FAILED Server"
      Output.WriteLine ""
    End If
      GetSubFolders strFolderName
    Next
End Sub

'**** The Code above is accurate **********

Function WMIDateStringToDate(sLastModified)
    WMIDateStringToDate = CDate(Mid(sLastModified, 7, 2) & "/" & _
    Mid(sLastModified, 5, 2) & "/" & Left(sLastModified, 4) _
    & " " & Mid (sLastModified, 9, 2) & ":" & _
    Mid(sLastModified, 11, 2) & ":" & Mid(sLastModified, 13, 2))
End Function

Open in new window

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
lasthopeAuthor Commented:
Both solutions work just as I wanted them to so rewarding points to both. Chose to use the array code because it is what I was attempting to do on my own.

Thanks to Kimputer and RobSampson for the awsome assistance!
0
RobSampsonCommented:
No problem. Thanks for the grade.
0
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.