0
votes

In my code I get the following error message

c:\dpdata_copy2.vbs(114,13) Microsoft VBScript compilation error: Expected identifier

line 114 points to a blank line so I assuemd it was throwing an error at the following line:

Lastprop = f.DateLastModified

in the code

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

strFolderName = "D:\1\production\Openjobs"

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

    'variables for getting last accessed property
    Dim fs, f 
    Set fs = CreateObject("Scripting.FileSystemObject") 

For Each objFolder in colSubfolders

    'get last modified date 
    Set f = fs.GetFolder(objFolder.Name) 
    Lastprop = f.DateLastModified
    'MsgBox(Lastprop)

            if ( DateDiff("m", f.DateLastModified, Now()) > 4) then 
                diffindates =  DateDiff("m", f.DateLastModified, Now())
                Set objShell = CreateObject("Shell.Application")
                Set objCopyFolder = objShell.NameSpace(ParentFolder) 

                OutputToLog("rem " & f.DateLastModified & ":" & objFolder.Name )

                outputtolog("move /Y """ & objFolder.Name & """ "  & ParentFolder)

                wscript.echo(diffindates & ":" & objFolder.Name & vbCr) 

            end if 

Next

Any ideas? or should I post the entire script up?

3
What's objFolder? Does it have a value for its Name property?Patrick Cuff
objFolder is the object key in a "for each" loop. In this case "For each objFolder in Colsubfolders" and colsubfolders = objWMIService.ExecQuery ("Associators of {Win32_Directory.Name='" & strFolderName & "'} " & "Where AssocClass = Win32_Subdirectory " _ & "ResultRole = PartComponent")phill
if you have the object alread why are you getting it again? does objFolder.DateLastModified work?Glennular
The code you posted works for me (other than using C:\Temp instead of D:\1\production\Openjobs). How are you running our script? Could there be a permissions issue on D:\1\production\Openjobs, or does some other process have this dir locked?Patrick Cuff
I got it working by checking to see if the objFolder.name is null. I'm waiting to see if it stops like it has last time. It has a about 800 directories to go through.. any ideas how to make it run faster?phill

3 Answers

0
votes

Are you running this using the Windows Scripting Host? If so, add //D as a parameter to CSCRIPT or WSCRIPT to activate the debug mode that let's you go through the stack and view all variables etc. in Visual Studio or any windows script debugger you have installed.

0
votes

This code works for me:

strFolderName = "C:\Temp"
strComputer = "MyComputerName"

set fs = CreateObject("Scripting.FileSystemObject")

set objWMIService = GetObject("winmgmts:" _ 
    & "{impersonationLevel=impersonate}!\\" _ 
    & strComputer & "\root\cimv2") 

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

For each objFolder in colsubfolders
    Set f = fs.GetFolder(objFolder.Name) 
    Lastprop = f.DateLastModified
    wscript.echo Lastprop
Next
-1
votes

Remove the line


Set f = fs.GetFolder(objFolder.Name)

and anywhere you use f within the for loop replace it with objFolder