2015-08-19 63 views
0

你好我试图调试这个脚本,我继承下面。错误是在第71行字符6.对象需要'oFile'VBS对象所需的错误,800A01A8

我没有任何vbs的经验,所以请温柔。该脚本会扫描并上传到文档归档服务器,赋予了它独特的文件名等。我还没有想出什么OFILE'又是:/

'Feb 18, 2005 

Dim oFSO 
Set oFSO = CreateObject("Scripting.FileSystemObject") 
hiddenCount = 0 
'Wscript.Echo Wscript.Arguments(0) 
If Wscript.Arguments.Count = 1 And oFSO.FolderExists(Wscript.Arguments(0)) Then 
    Set scanFiles = oFSO.GetFolder(Wscript.Arguments(0)).Files 
    For Each oFile In scanFiles 
    If oFile.Attributes and 2 Then 
    hiddenCount = hiddenCount + 1 
End If 
     Next 
Else 
    Set scanFiles = WScript.Arguments 
End If 
fileCount = scanFiles.Count - hiddenCount 
'Wscript.Echo hiddenCount 
'WScript.Echo fileCount 
'WScript.Quit() 
Set oIE = WScript.CreateObject("InternetExplorer.Application") 
oIE.left=50 ' window position 
oIE.top = 100 ' and other properties 
oIE.height = 300 
oIE.width = 350 
oIE.menubar = 0 ' no menu 
oIE.toolbar = 0 
oIE.statusbar = 1 
oIE.navigate "http://gisweb/apps/doc_archive/scan_login.php?file_count="&fileCount 
'WScript.Echo fileCount 
oIE.visible = 1 

' Important: wait till MSIE is ready 
    Do While (oIE.Busy)  
    Loop 

' Wait till the user clicks the OK button 
' Use the CheckVal function 
' Attention: Thanks to a note from M. Harris, we can make 
' the script a bit more fool proof. We need to catch the case 
' that the user closes the form without clicking the OK button. 
On Error Resume Next 
Do      ' Wait till OK button is clicked 
    WScript.Sleep 400 
Loop While (oIE.document.script.CheckVal()=0) 

' If an error occur, because the form is closed, quit the 
' script 
If err <> 0 Then 
    WScript.Echo "Sorry, a run-time error occured during checking" & _ 
       " the OK button " & vbCRLF & _ 
       "Error: " & err.number & " " & _ 
       "I guess the form was getting closed..." 
    WScript.Quit  ' end script 
End if 
On Error Goto 0 ' switch error handling off 

' User has clicked the OK button, retrieve the values 
docList = oIE.Document.ValidForm.doc_id_list.Value 
'MsgBox doc_id 
For i = 0 To 100000 
    x = 1 
Next 
oIE.Quit()    ' close Internet Explorer 
Set oIE = Nothing  ' reset object variable 


docArray = Split(docList,",") 
i = 0 
For Each oFile In scanFiles 
    If Not oFile.Attributes And 2 Then **ERROR HERE** 
    ext = oFSO.GetExtensionName(oFile) 
    filename = "p"&right("000000"&docArray(i),6)&"."&ext 
    base = Int(docArray(i)/500) * 500 
    subdir = "d"&right("000000"&base,6) 
    oFSO.CopyFile oFile, "\\ditgis02\Enterprise_GIS\doc_archive\raw\"&subdir&"\"&filename, True 
    i = i + 1 
    End If 
Next 
If Wscript.Arguments.Count = 1 And oFSO.FolderExists(Wscript.Arguments(0)) Then 
    Set WshShell = WScript.CreateObject("WScript.Shell") 
    intButton = WshShell.Popup (fileCount&" file(s) logged and copied! Do you want to delete temporary scan files?",0,"Done!",4) 
    If intButton = 6 Then 
     For Each oFile In scanFiles 
      oFile.Delete 
     Next 
    End If 
Else 
    WScript.Echo(fileCount&" file(s) logged and copied!") 
End If 
WScript.Quit()   ' Ready 
' End 
+1

PHP如何介入? –

+0

你如何运行脚本?你传递给它什么参数? – Bond

+0

我们将pdf文档拖入脚本 –

回答

0

它看起来的问题,如果你最初可能出现测试失败:

If Wscript.Arguments.Count = 1 And oFSO.FolderExists(Wscript.Arguments(0)) Then 
    ... 
Else 
    Set scanFiles = WScript.Arguments 
End If 

你的scanFiles变量设置为自变量,而不是文件的集合。后来,近线71(其中的错误发生时),你处理scanFiles,就好像它是一个Files收集和试图访问其File对象之一的Attributes属性:

For Each oFile In scanFiles 
    If Not oFile.Attributes And 2 Then **ERROR HERE** 
    ... 
Next 

这会不会是因为scanFiles可能是Arguments集合。所以我认为你需要修复你的初始Else子句,以终止你的脚本或者提供某种“默认”收集Files

+0

谢谢,“默认”文件目前是'oFile'吗?如何创建新的“默认”文件部分? –

+0

如果脚本没有收到有效的文件夹作为参数,您希望脚本执行什么操作? – Bond

+0

我想我想终止,我将如何在'设置扫描文件'中设置文件夹?只是给它一个路径?再次感谢。对不起,这有点高于我的头。 –