如何更正VBscript运行时错误:输入超过文件结尾

如何更正VBscript运行时错误:输入超过文件结尾,vbscript,Vbscript,我得到这个代码的以下错误。你能告诉我哪里错了吗?第71行是“urls2=objInputFile.ReadAll” 第71行 字符1 错误:输入超过文件末尾 代码:800A003E 来源:Microsoft VBScript运行时错误 inputfile = "C:\Evernote.html" outputfolder = "c:\" msgbox("launched. press ok to continue") 'create urls1.txt Set objFileSystem

我得到这个代码的以下错误。你能告诉我哪里错了吗?第71行是“urls2=objInputFile.ReadAll”

第71行 字符1 错误:输入超过文件末尾 代码:800A003E 来源:Microsoft VBScript运行时错误

inputfile = "C:\Evernote.html"
outputfolder = "c:\"


msgbox("launched. press ok to continue")


'create urls1.txt
Set objFileSystem = CreateObject("Scripting.fileSystemObject")
Set objOutputFile = objFileSystem.CreateTextFile(outputfolder & "urls1.txt", TRUE)

'read inputfile (evernote exported html) 
Set objFileSystem = CreateObject("Scripting.fileSystemObject")
Set objInputFile = objFileSystem.OpenTextFile(inputfile, 1)
html = objInputFile.ReadAll
objInputFile.Close


'split html var
html = Split(html, "<tr><td><b>Source:</b></td><td><a href=""")

'loop through html array and clean up the results so you get just the urls
'and write them to urls1.txt
For i = 1 To UBound(html)
checkA = InStr(html(i), """")
    if checkA > 1 then
        html(i) = Split(html(i), """")
        urls = html(i)(0)
        objOutputFile.WriteLine(urls)
    end if
Next



'remove duplicates

'create urls2.txt
Set objFileSystem = CreateObject("Scripting.fileSystemObject")
Set objOutputFile = objFileSystem.CreateTextFile(outputfolder & "urls2.txt", TRUE)

'read urls1.txt and remove duplicates and write results to urls2.txt
Set objFS = CreateObject("Scripting.FileSystemObject")
strFile = outputfolder & "urls1.txt"
Set objFile = objFS.OpenTextFile(strFile)
Set d = CreateObject("Scripting.Dictionary")
Do Until objFile.AtEndOfStream
strLine = objFile.ReadLine
If Not InStr(strLine,"--------") >0 Then
    If Not d.Exists(strLine) Then 
        d.Add strLine , 0
    End If 
End If 
Loop
x=d.Items
For Each strKey In d.keys
objOutputFile.WriteLine(strKey)
Next



'sort alphabetically



'read urls2.txt and sort everything alphabetically


'read urls2.txt
Set objFileSystem = CreateObject("Scripting.fileSystemObject")
Set objInputFile = objFileSystem.OpenTextFile(outputfolder & "urls2.txt", 1)
urls2 = objInputFile.ReadAll
objInputFile.Close

'split each line into array
urls2 = Split(urls2, VBCrLf)

'sort urls2 array by alphabet with bubble sort method

For i = (UBound(urls2) - 1) to 0 Step -1
For j= 0 to i
    If UCase(urls2(j)) > UCase(urls2(j+1)) Then
        strHolder = urls2(j+1)
        urls2(j+1) = urls2(j)
        urls2(j) = strHolder
    End If
Next
Next

'write the sorted version of urls2.txt in urlsfinal.txt

'create urlsfinal.txt
Set objFileSystem = CreateObject("Scripting.fileSystemObject")
Set objOutputFile = objFileSystem.CreateTextFile(outputfolder & "urlsfinal.txt", TRUE)

'write all sorted vars from urls2 array to urlsfinal.txt
For i = 0 to UBound(urls2)
objOutputFile.WriteLine(urls2(i))
next



msgbox("all done")
inputfile=“C:\Evernote.html”
outputfolder=“c:\”
msgbox(“已启动。按ok继续”)
'创建urls1.txt
设置objFileSystem=CreateObject(“Scripting.fileSystemObject”)
设置objOutputFile=objFileSystem.CreateTextFile(outputfolder&“urls1.txt”,TRUE)
'读取输入文件(evernote导出的html)
设置objFileSystem=CreateObject(“Scripting.fileSystemObject”)
设置objInputFile=objFileSystem.OpenTextFile(inputfile,1)
html=objInputFile.ReadAll
objInputFile.Close
'拆分html变量

html=Split(html,“Source:问题是您的源文件
urls2.txt
为空。原因是您在写入文件后没有关闭这些文件。您需要在完成写入
urls1.txt
urls2.txt
后添加这些文件

 objOutputFile.Close
此外,您不需要每次访问文件时都不断地重新创建
objFileSystem
的实例,您可以在顶部实例化一次

确保自己是一个好的内存公民,并销毁代码中设置的所有对象

Set objFileSystem = Nothing