Microsoft VBScript运行时错误:输入文件末尾错误

时间:2014-11-12 03:49:51

标签: command-line vbscript

我收到此错误:

" C:\ se2.vbs(28,6)Microsoft VBScript运行时错误:输入文件末尾"

当我运行我的脚本时(我用斜体字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

如果是InStr(oFSO.OpenTextFile(path).ReadAll,strSearchFor)> 0然后

            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."

请帮忙!谢谢!

2 个答案:

答案 0 :(得分:1)

看起来其中一个文件的大小为零。证据:

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

输出:

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

答案 1 :(得分:0)

我发现了问题。脚本在BLANK TEXT FILE中搜索字符串时发生错误。我尝试添加这个:

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

    'Process text file then search for string.

END IF