Microsoft VBScript runtime error: Input past end o

2019-03-04 23:07发布

I am getting this error:

"C:\se2.vbs(28, 6) Microsoft VBScript runtime error: Input past end of file"

when I run my script (I italicized LINE 28):

Dim strInput
Dim filesys
Dim path
Set filesys=CreateObject("Scripting.FileSystemObject")
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set oFSO = CreateObject("Scripting.FileSystemObject")

objStartFolder = "C:\Program Files\Apache Software Foundation\Tomcat 7.0_Tomcat7_1010\webapps\Geniisys\" 'Directory to search
objTempFolder = "C:\Users\njediaz\Desktop\temp\"
objOutputFile = "C:\Users\njediaz\Desktop\output\files.txt"

strInput = InputBox("Enter file to search (case sensitive):")
strSearchFor = strInput

ShowSubfolders objFSO.GetFolder(objStartFolder)

Sub ShowSubFolders(Folder)

   'Wscript.Echo Folder.Path

   For Each objFile in Folder.files

      ' Wscript.Echo Folder.Path & "\" & objFile.Name

       path = Folder.Path & "\" & objFile.Name

If InStr(oFSO.OpenTextFile(path).ReadAll, strSearchFor) > 0 Then

            filesys.CopyFile path , objTempFolder & objFile.Name
        Else
            WScript.Sleep (100)
        END If

   Next

   For Each Subfolder in Folder.SubFolders
       ShowSubFolders Subfolder
   Next
End Sub
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'Script to log common files

Set fs = CreateObject("Scripting.FileSystemObject")
'Log file name
Set logFile = fs.OpenTextFile(objOutputFile, 2, True)
'Directory you want listed
Set folder = fs.GetFolder(objTempFolder)

Set files = folder.Files
  For Each file in files
    logFile.writeline(file.name)
  Next
logFile.close
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'Script to delete

Const DeleteReadOnly = TRUE

Set objFSO = CreateObject("Scripting.FileSystemObject")
objFSO.DeleteFile(objTempFolder & "*"), DeleteReadOnly

MsgBox "Done."

Help please! Thanks!

2条回答
做自己的国王
2楼-- · 2019-03-04 23:38

I found out the problem. The error occurred when the script searched for a string in a BLANK TEXT FILE. I tried adding this:

IF oFSO.GetFile(path).size <> 0 then    

    'Process text file then search for string.

END IF
查看更多
聊天终结者
3楼-- · 2019-03-04 23:42

Looks like one of the files has zero size. Evidence:

Option Explicit

Const ForReading = 1

Dim goFS : Set goFS = CreateObject("Scripting.FileSystemObject")

Dim oFile
For Each oFile In goFS.GetFolder("..\data\26878933").Files
    WScript.Echo oFile.Path, oFile.Size
    WScript.Echo oFile.OpenAsTextStream(ForReading).ReadAll()
    WScript.Echo "------"
Next

output:

cscript 26878933.vbs
..\data\26878933\a.txt 3
a

------
..\data\26878933\b.txt 0
26878933.vbs(10, 5) Microsoft VBScript runtime error: Input past end of file
查看更多
登录 后发表回答