【问题标题】:Microsoft VBScript runtime error: Input past end of file errorMicrosoft VBScript 运行时错误:输入超过文件结尾错误
【发布时间】:2023-04-05 04:44:01
【问题描述】:

我收到此错误:

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

请帮忙!谢谢!

【问题讨论】:

  • 'objStartFolder' 下是否有一些文件夹?您的代码假定“objStartFolder”下仅存在数据文件。如果文件夹存在,您的代码会尝试打开没有文件部分的路径作为文本文件。例如,oFSO.OpenTextFile("C:\Program Files\Apache Software Foundation\Tomcat 7.0_Tomcat7_1010\webapps\Geniisys\someSubDir\") 可能会出现相同的错误消息。
  • 您好 Fumu 7,我尝试了您的建议,即使扫描没有文本文件的文件夹,代码也能正常工作。不过感谢您的帮助!

标签: command-line vbscript


【解决方案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

【讨论】:

  • 嗨。是的,这确实是错误!我刚刚发现了。谢谢您的帮助。我放了这个 IF 语句来捕捉空白文本文件:IF oFSO.GetFile(path).size <> 0 then 'Process text file then search for string. END IF
【解决方案2】:

我发现了问题。脚本在空白文本文件中搜索字符串时发生错误。我试着添加这个:

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

    'Process text file then search for string.

END IF

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-10-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多