hnugz
02-22-2006, 07:18 PM
I am trying to create a search script but I am running into an out of memory error. Here is the search subroutine which loops multiple times:
sub SubSearch()
path = folderarray(arraycounter) 'set path to current folder to search
if arraycounter > 0 then
temp = arraycounter - 1
folderarray(temp) = 0
end if
' Set fso = server.CreateObject("Scripting.FileSystemObject")
set fo = fso.getfolder(path)
' response.write(fo & "<br>")
for each subfolder in fo.subfolders
temppath = subfolder
redim preserve folderarray(counter)
folderarray(counter) = temppath
counter = counter + 1
next
for each file in fo.files
if fso.getextensionname(file) = "mht" then
set readfile=fso.opentextfile(file,1,false)
set readfilename=fso.getfile(file)
if file.size > 0 then 'if something in the file, read it MAY NEED TO CHANGE
file=readfile.readall
else
exit for
end if
urlfilename = replace(mid(readfilename, 29),"\","/")
urlfilename = replace(urlfilename," ","%20")
'Necessary to keep it from searching through the picture garbage text
find_html = instr(file, "</html>")
file = left(file, find_html)
'The actual search part
isinfile = instr(1, file, search, 1)
if isinfile > 0 then
'Pulls the page title out
title_str = instr(file, "<title>")
title_str = title_str + 7 'adds 7 to start right after <title>
title_end = instr(file, "</title>")
title_read = title_end - title_str
number = number + 1
response.write(number & ": ") %><a href=<% response.write(fusionurl & urlfilename) %> target="_blank"><% response.write(mid(file, title_str, title_read)) %></a><%
response.write("<br><br>")
starthere = isinfile - 10
end if
set readfile=nothing
set readfilename=nothing
end if
next
arraycounter = arraycounter + 1
' set fso=nothing
set fo=nothing
' response.write("Arraycounter = " & arraycounter & " and Counter = " & counter & "<br>")
if arraycounter = counter then 'if no other folders to search, then done
SubNotFound()
response.write("Script Done.<br>")
else 'if more folders to search, call SubSearch
SubSearch
end if
end sub
It works as long as there are less than about 130 documents. It gives me the error about 9 lines down, set fo = fso.getfolder(path). I made sure to set fo =nothing at the bottom, any ideas why I am getting this? Thanks.
sub SubSearch()
path = folderarray(arraycounter) 'set path to current folder to search
if arraycounter > 0 then
temp = arraycounter - 1
folderarray(temp) = 0
end if
' Set fso = server.CreateObject("Scripting.FileSystemObject")
set fo = fso.getfolder(path)
' response.write(fo & "<br>")
for each subfolder in fo.subfolders
temppath = subfolder
redim preserve folderarray(counter)
folderarray(counter) = temppath
counter = counter + 1
next
for each file in fo.files
if fso.getextensionname(file) = "mht" then
set readfile=fso.opentextfile(file,1,false)
set readfilename=fso.getfile(file)
if file.size > 0 then 'if something in the file, read it MAY NEED TO CHANGE
file=readfile.readall
else
exit for
end if
urlfilename = replace(mid(readfilename, 29),"\","/")
urlfilename = replace(urlfilename," ","%20")
'Necessary to keep it from searching through the picture garbage text
find_html = instr(file, "</html>")
file = left(file, find_html)
'The actual search part
isinfile = instr(1, file, search, 1)
if isinfile > 0 then
'Pulls the page title out
title_str = instr(file, "<title>")
title_str = title_str + 7 'adds 7 to start right after <title>
title_end = instr(file, "</title>")
title_read = title_end - title_str
number = number + 1
response.write(number & ": ") %><a href=<% response.write(fusionurl & urlfilename) %> target="_blank"><% response.write(mid(file, title_str, title_read)) %></a><%
response.write("<br><br>")
starthere = isinfile - 10
end if
set readfile=nothing
set readfilename=nothing
end if
next
arraycounter = arraycounter + 1
' set fso=nothing
set fo=nothing
' response.write("Arraycounter = " & arraycounter & " and Counter = " & counter & "<br>")
if arraycounter = counter then 'if no other folders to search, then done
SubNotFound()
response.write("Script Done.<br>")
else 'if more folders to search, call SubSearch
SubSearch
end if
end sub
It works as long as there are less than about 130 documents. It gives me the error about 9 lines down, set fo = fso.getfolder(path). I made sure to set fo =nothing at the bottom, any ideas why I am getting this? Thanks.