Vbscript 错误:需要对象';objDIR';代码:800A01A8
好的,我在发布代码之前遇到的问题。。。我犯了这个错误 错误:需要对象;'objDIR'代码:第19行800A01A8 当我使用“错误时继续下一步”和“错误时转到0”跳过它时,我会得到所需的“错误对象”:“strFile”第22行当我跳过它时,它会告诉我上一个下一步不是集合。。。在我加入获取.tif和.tiff文件的步骤之前,这个程序工作得非常出色。现在,即使我删除我添加的内容,它也不起作用 该程序的功能是在“源目录”中搜索可归档的文件,然后将这些文件移动到“目标目录”,然后将其检查为不可归档,这样就不会再次拾取这些文件。它还记录了哪些文件是用日期戳等复制的。就像我说的,它工作得很好,但经过几个小时的修补后,无法找出哪里出了问题Vbscript 错误:需要对象';objDIR';代码:800A01A8,vbscript,Vbscript,好的,我在发布代码之前遇到的问题。。。我犯了这个错误 错误:需要对象;'objDIR'代码:第19行800A01A8 当我使用“错误时继续下一步”和“错误时转到0”跳过它时,我会得到所需的“错误对象”:“strFile”第22行当我跳过它时,它会告诉我上一个下一步不是集合。。。在我加入获取.tif和.tiff文件的步骤之前,这个程序工作得非常出色。现在,即使我删除我添加的内容,它也不起作用 该程序的功能是在“源目录”中搜索可归档的文件,然后将这些文件移动到“目标目录”,然后将其检查为不可归档,这
Option Explicit
Dim objLogFile, objFS, strFolder, strDestination, objFolder, eFolder, strFileName,
strExtension, objDIR, strFile
Set objFS = CreateObject("Scripting.FileSystemObject")
strFolder = "S:\Source"
strDestination = "Z:\Destination"
Set objFolder = objFS.GetFolder(strFolder)
Set objLogFile = objFS.OpenTextFile ("S:\Log.txt",2,true)
Go(objFolder)
Sub Go(objDIR)
objLogFile.Writeline "Script started at " & Now
If objDIR <> "\System Volume Information" Then
For Each eFolder In objDIR.SubFolders
Go eFolder
Next
On Error Resume Next
For Each strFile In objDIR.Files
On Error GoTo 0
strFileName = strFile.Name
strExtension = objFS.GetExtensionName(strFile)
If strExtension = "pdf" Then
If objFS.GetFile(strFile).Attributes And 32 Then
objFS.CopyFile strFile , strDestination & strFileName, True
objLogFile.Writeline "Copied " & strFileName & Now
Else
objFS.GetFile(strFile).Attributes = objFS.GetFile(strFile).Attributes XOR 32
End If
End If
If strExtension = "tif" Then
If objFS.GetFile(strFile).Attributes And 32 Then
objFS.CopyFile strFile , strDestination & strFileName, True
objLogFile.Writeline "Copied " & strFileName & Now
Else
objFS.GetFile(strFile).Attributes = objFS.GetFile(strFile).Attributes XOR 32
End If
End If
If strExtension = "tiff" Then
If objFS.GetFile(strFile).Attributes And 32 Then
objFS.CopyFile strFile , strDestination & strFileName, True
objLogFile.Writeline "Copied " & strFileName & Now
Else
objFS.GetFile(strFile).Attributes = objFS.GetFile(strFile).Attributes XOR 32
End If
End If
Next
objFS.GetFile(strFile).Attributes = objFS.GetFile(strFile).Attributes XOR 32
End If
objLogFile.Writeline "Script ended at " & Now
objLogFile.close
WScript.Quit()
End Sub
选项显式
Dim objLogFile、objFS、strFolder、strDestination、objFolder、eFolder、strFileName、,
strExtension、objDIR、strFile
设置objFS=CreateObject(“Scripting.FileSystemObject”)
strFolder=“S:\Source”
strDestination=“Z:\Destination”
设置objFolder=objFS.GetFolder(strFolder)
设置objLogFile=objFS.OpenTextFile(“S:\Log.txt”,2,true)
转到(objFolder)
副Go(objDIR)
objLogFile.Writeline“脚本开始于”&现在
如果objDIR“\System Volume Information”,则
对于objDIR.SubFolders中的每个eFolder
付账
下一个
出错时继续下一步
对于objDIR.Files中的每个strFile
错误转到0
strFileName=strFile.Name
strExtension=objFS.GetExtensionName(strFile)
如果strExtension=“pdf”,则
如果objFS.GetFile(strFile).Attributes和32,则
objFS.CopyFile strFile,strDestination和strFileName,True
objLogFile.Writeline“已复制”&strFileName&Now
其他的
objFS.GetFile(strFile).Attributes=objFS.GetFile(strFile).Attributes XOR 32
如果结束
如果结束
如果strExtension=“tif”,则
如果objFS.GetFile(strFile).Attributes和32,则
objFS.CopyFile strFile,strDestination和strFileName,True
objLogFile.Writeline“已复制”&strFileName&Now
其他的
objFS.GetFile(strFile).Attributes=objFS.GetFile(strFile).Attributes XOR 32
如果结束
如果结束
如果strExtension=“tiff”,则
如果objFS.GetFile(strFile).Attributes和32,则
objFS.CopyFile strFile,strDestination和strFileName,True
objLogFile.Writeline“已复制”&strFileName&Now
其他的
objFS.GetFile(strFile).Attributes=objFS.GetFile(strFile).Attributes XOR 32
如果结束
如果结束
下一个
objFS.GetFile(strFile).Attributes=objFS.GetFile(strFile).Attributes XOR 32
如果结束
objLogFile.Writeline“脚本结束于”&现在
objLogFile.close
WScript.Quit()
端接头
要解决现实世界中的问题,您应该考虑:
c:\windows
或c:\System Volume Information
将降低风险并提高效率dir/s/b c:\can\di\date\*.tiff>>稍后处理。txt
可以提供一个“干净”的文件列表,以便使用.vbs处理C:\System Volume Information
,但比较了\System Volume Information
(无驱动器)
不太明显的是:你不能使用
On Error Resume Next
For Each strFile In objDIR.Files
On Error GoTo 0
“跳过讨厌元素的循环”。OERN不是这样工作的。要解决现实世界中的问题,您应该考虑:
c:\windows
或c:\System Volume Information
将降低风险并提高效率dir/s/b c:\can\di\date\*.tiff>>稍后处理。txt
可以提供一个“干净”的文件列表,以便使用.vbs处理C:\System Volume Information
,但比较了\System Volume Information
(无驱动器)
不太明显的是:你不能使用
On Error Resume Next
For Each strFile In objDIR.Files
On Error GoTo 0
“跳过讨厌元素的循环”。OERN就是不能那样工作。我修复了代码。。。我不确定到底出了什么问题,但我清理了脚本,它又重新工作了。这是代码,以防其他人需要
Set objFS = CreateObject("Scripting.FileSystemObject")
strFolder = "S:\Source"
strDestination = "Z:\Destination\"
Set objFolder = objFS.GetFolder(strFolder)
Set objLogFile = objFS.OpenTextFile ("S:Logs.txt",2,true)
Go(objFolder)
Sub Go(objDIR)
objLogFile.Writeline "Script started at " & Now
If objDIR <> "\System Volume Information" Then
For Each eFolder In objDIR.SubFolders
Go eFolder
Next
For Each strFile in objDIR.files
strFileName = strFile.Name
strExtension = objFS.GetExtensionName(strFile)
If strExtension = "pdf" Then
If objFS.GetFile(strFile).Attributes And 32 Then
objFS.CopyFile strFile , strDestination & strFileName, True
objLogFile.Writeline "Copied " & strFileName & Now
objFS.GetFile(strFile).Attributes = objFS.GetFile(strFile).Attributes XOR 32
End If
End If
If strExtension = "tif" Then
If objFS.GetFile(strFile).Attributes And 32 Then
objFS.CopyFile strFile , strDestination & strFileName, True
objLogFile.Writeline "Copied " & strFileName & Now
objFS.GetFile(strFile).Attributes = objFS.GetFile(strFile).Attributes XOR 32
End If
End If
If strExtension = "tiff" Then
If objFS.GetFile(strFile).Attributes And 32 Then
objFS.CopyFile strFile , strDestination & strFileName, True
objLogFile.Writeline "Copied " & strFileName & Now
objFS.GetFile(strFile).Attributes = objFS.GetFile(strFile).Attributes XOR 32
End If
End If
Next
End If
objLogFile.Writeline "Script ended at " & Now
objLogFile.close
WScript.Quit()
End Sub
Set objFS=CreateObject(“Scripting.FileSystemObject”)
strFolder=“S:\Source”
strDestination=“Z:\Destination\”
设置objFolder=objFS.GetFolder(strFolder)
设置objLogFile=objFS.OpenTextFile(“S:Logs.txt”,2,true)
转到(objFolder)
副Go(objDIR)
objLogFile.Writeline“脚本开始于”&现在
如果objDIR“\System Volume Information”,则
对于objDIR.SubFolders中的每个eFolder
付账
下一个
对于objDIR.xml文件中的每个strFile
strFileName=strFile.Name
strExtension=objFS.GetExtensionName(strFile)
如果strExtension=“pdf”,则
如果objFS.GetFile(strFile).Attributes和32,则
objFS.CopyFile strFile,strDestination和strFileName,True
objLogFile.Writeline“已复制”&strFileName&Now
objFS.GetFile(strFile).Attributes=objFS.GetFile(strFile).Attributes XOR 32
如果结束
如果结束
如果strExtension=“tif”,则
如果objFS.GetFile(strFile).Attributes和32,则
objFS.CopyFile strFile,strDestination&