在我的代码中,我收到以下错误消息
c:\ dpdata_copy2.vbs(114,13)Microsoft VBScript编译错误:预期 标识符
第114行指向一个空白行,所以我认为它在以下行引发错误:
Lastprop = f.DateLastModified
代码中的
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
有什么想法吗?或者我应该发布整个脚本吗?
答案 0 :(得分:0)
您是否使用Windows Scripting Host运行此操作?如果是这样,将// D作为参数添加到CSCRIPT或WSCRIPT以激活调试模式,让您通过堆栈查看Visual Studio中的所有变量等,或者安装的任何Windows脚本调试器。
答案 1 :(得分:0)
此代码适用于我:
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
答案 2 :(得分:-1)
删除行
Set f = fs.GetFolder(objFolder.Name)
以及在for循环中使用f的任何地方都将其替换为objFolder