2015-08-19 78 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

我想我想終止,我將如何在'設置掃描文件'中設置文件夾?只是給它一個路徑?再次感謝。對不起,這有點高於我的頭。 –