我急需幫助,我試圖搜索包含超過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
瘋狂的部分是不是,它給我的結果與鏈接和適量的文件。 –