tags:

views:

467

answers:

3

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?

A: 

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.

svinto
I added //D to the command line when I ran c:\dpdata_copy2.vbs //D and it opened a blank page in Microsoft Script Debugger. I then opened the file in application and it does not allow me to step through the script
phill
Try //X instead of //D.
Patrick Cuff
A: 

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
Patrick Cuff
A: 

Remove the line


Set f = fs.GetFolder(objFolder.Name)

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

Tester101
-1: objFolder.DateLastModified results in "Microsoft VBScript runtime error: Object doesn't support this property or method: 'objFolder.DateLastModified'"
Patrick Cuff