<%
response.buffer=true
onefile search engine (ofsearch v1.0)
copyright ?000 sixto luis santos <sixtos@prtc.net>
all rights reserved
note:
this program is freeware. this program is not in the public domain.
you can freely use this program in your own site.
you cannot re-distribute the code, by any means,
without the express written authorization by the author.
use this program at your own risk.
globals ————————————–
———————————————-
const validfiles = "htmltxt"
const rootfld = "./"
dim matched
dim regex
dim gettitle
dim fs
dim rflen
dim rootfolder
dim doccount
dim docmatchcount
dim matchedcount
———————————————-
procedure: searchfiles()
———————————————-
public sub searchfiles(folderpath)
dim fsfolder
dim fsfolder2
dim fsfile
dim fstext
dim filetext
dim filetitle
dim filetitlematch
dim matchcount
dim outputline
get the starting folder
set fsfolder = fs.getfolder(folderpath)
iterate thru every file in the folder
for each fsfile in fsfolder.files
compare the current file extension with the list of valid target files
if instr(1, validfiles, right(fsfile.name, 3), vbtextcompare) > 0 then
doccount = doccount + 1
open the file to read its content
set fstext = fsfile.openastextstream
filetext = fstext.readall
apply the regex search and get the count of matches found
matchcount = regex.execute(filetext).count
matchedcount = matchedcount + matchcount
if matchcount > 0 then
docmatchcount = docmatchcount + 1
apply another regex to get the html documents title
set filetitlematch = gettitle.execute(filetext)
if filetitlematch.count > 0 then
strip the title tags
filetitle = trim(replace(mid(filetitlematch.item(0),8),"</title>","",1,1,1))
in case the title is empty
if filetitle = "" then
filetitle = "no title (" & fsfile.name & ")"
end if
else
create an alternate entry name (if no title found)
filetitle = "no title (" & fsfile.name & ")"
end if
create the entry line with proper formatting
add the entry number
outputline = " <b>" & docmatchcount & ".</b> "
add the document name and link
outputline = outputline & "<a href=" & chr(34) & rootfld & replace(mid(fsfile.path,
rflen),"\","/") & chr(34) & "><b>"
outputline = outputline & filetitle & "</b></a>"
add the document information
outputline = outputline & "<font size=1><br> criteria matched " & matchcount
& " times – size: "
outputline = outputline & formatnumber(fsfile.size / 1024,2 ,-1,0,-1) & "k bytes"
outputline = outputline & " – last modified: " & formatdatetime
(fsfile.datelastmodified,vbshortdate) & "</font><br>"
display entry
response.write outputline
response.flush
end if
fstext.close
end if
next
iterate thru each subfolder and recursively call this procedure
for each fsfolder2 in fsfolder.subfolders
searchfiles fsfolder2.path
next
set filetitlematch = nothing
set fstext = nothing
set fsfile = nothing
set fsfolder2 = nothing
set fsfolder = nothing
end sub
———————————————-
procedure: search()
———————————————-
sub search(searchstring)
dim i
dim fkeys
dim fitems
set fs = createobject("scripting.filesystemobject")
set gettitle = new regexp
set regex = new regexp
with regex
.global = true
.ignorecase = true
.pattern = trim(searchstring)
end with
with gettitle
.global = false
.ignorecase = true
.pattern = "<title>(.|\n)*</title>"
end with
rootfolder = server.mappath(rootfld)
if right(rootfld,1) <> "/" then
rootfld = rootfld & "/"
end if
if right(rootfolder, 1) <> "\" then
rootfolder = rootfolder & "\"
end if
rflen = len(rootfolder) + 1
searchfiles rootfolder
if matchedcount = 0 then
response.write " <b>no matches found.</b><br>"
end if
set regex = nothing
set gettitle = nothing
set fs = nothing
end sub
%>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=windows-1252">
<meta http-equiv="content-language" content="en-us">
<title>onefile search 1.0</title>
</head>
<body bgcolor="#ffffff" link="#660000" vlink="#008000">
<font face="tahoma,arial" size="2">
<table border="0" width="100%" cellspacing="0" cellpadding="0">
<tr>
<td width="100%" colspan="2"></td>
</tr>
<tr>
<td width="50%" bgcolor="#000000">
<form method="get">
<table border="0" width="100%">
<tr>
<td width="33%" align="right"><font color="#ffffff" size="2" face="tahoma,arial"><b>search
for </b></font></td>
<td width="33%"><input type="text" size="20" value="<%=request.querystring("query")%>"
name="query"></td>
<td width="34%"><input type="submit" name="search" value="search"></td>
</tr>
</table>
</form>
</td>
<td width="50%" bgcolor="#000000"></td>
</tr>
<tr>
<td width="100%" colspan="2" bgcolor="#000000"></td>
</tr>
<tr>
<td width="50%" bgcolor="#808080">
<table border="0" width="100%">
<tr>
<td width="33%" align="right"><font face="tahoma,arial" size="1"
color="#ffffff"><b>tip:</b></font></td>
<td width="67%"><font color="#ffffff" face="tahoma,arial" size="1">search by using <a
href="http://msdn.microsoft.com/scripting/default.htm?/scripting/vbscript/doc/jsgrpregexpsyntax.htm">regula
r expresions</a>.</font></td>
</tr>
</table>
</td>
<td width="50%" bgcolor="#808080"></td>
</tr>
</table>
<%
if trim(request.querystring("query")) <> "" then
%>
<hr>
<table border="0" width="100%" bgcolor="#808080" cellspacing="0" cellpadding="0">
<tr>
<td width="100%"><font color="#ffffff" size="2"> your search for <b><%
=request.querystring("query")%></b> found the following documents:</font></td>
</tr>
</table>
<br><br>
<%
response.flush
search request.querystring("query")
if doccount > 0 then
%>
<br>
<font size=1>
(the search criteria "<%=request.querystring("query")%>" found <%=matchedcount%> times in <%
=docmatchcount%> of <%=doccount%> documents.)
</font>
<%
end if
end if
%>
<br><br>
<hr><div align="center">
<font size=1>
onefile search engine v1.0<br>
copyright?000 <a href="mailto:sixtos@prtc.net">sixto luis santos</a>.
all rights reserved
</font></div>
</font>
</body>
</html>
<%
response.end
%>
