我急需帮助,我试图搜索包含超过5000个pdf的文件夹目录中的文本字符串,代码已经过测试并且使用少于100个PDF和它的工作原理,但一旦达到极限,需要花费5-10分钟才能得出结果。任何帮助非常感谢:在文件夹中搜索pdf文本字符串的更快方法
'<%
'Search Text
Dim strtextToSearch
strtextToSearch = Request("TextToSearch")
'Now, we want to search all of the files
Dim fso
'Constant to read
Const ForReading = 1
Set fso = Server.CreateObject("Scripting.FileSystemObject")
'Specify the folder path to search.
Dim FolderToSearch
FolderToSearch = "C:\inetpub\site\Files\allpdfs\"
'Proceed if folder exists
if fso.FolderExists(FolderToSearch) then
Dim objFolder
Set objFolder = fso.GetFolder(FolderToSearch)
Dim objFile, objTextStream, strFileContents, bolFileFound
bolFileFound = False
Dim FilesCounter
FilesCounter = 0 'Total files found
For Each objFile in objFolder.Files
Set objTextStream = fso.OpenTextFile(objFile.Path,ForReading)
'Read the content
strFileContents = objTextStream.ReadAll
If InStr(1,strFileContents,strtextToSearch,1) then
'%>
<a href="http://go.to.mysite.com/files/allpdfs/<%Response.Write objFile.Name%>" target="_blank">
'<%
Response.Write objFile.Name & "</a><br>"
FilesCounter = FilesCounter + 1
End If
objTextStream.Close
Next
if FilesCounter = 0 then
Response.Write "Sorry, No matches found."
else
Response.Write "Total files found : " & FilesCounter
end if
'Destroy the objects
Set objTextStream = Nothing
Set objFolder = Nothing
else
Response.Write "Sorry, invalid folder name"
end if
Set fso = Nothing
%>
PDF文件是二进制文件,您在这里将它们视为常规文本,这是不正确的。无论如何,您的当前结果很可能不正确,即使是100个文件也是如此。 – yms
疯狂的部分是不是,它给我的结果与链接和适量的文件。 –