Link to home
Start Free TrialLog in
Avatar of lasthope
lasthope

asked on

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
SOLUTION
Avatar of Kimputer
Kimputer

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of lasthope
lasthope

ASKER

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!
No problem. Thanks for the grade.