Mailing List Archive: 49091 messages
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

[REBOL] search directory

From: rchristiansen::pop::isdfa::sei-it::com at: 1-Nov-2000 18:33

Following is a script I created for searching for a keyword among .html files in a single directory. If you see any glaring potential problems, I'm listening. Otherwise, it works great. -Ryan REBOL [] print "Content-Type: text/html^/" ; --- CGI INPUT ("GET" METHOD) --- cgi-input: make object! decode-cgi system/options/cgi/query-string ; --- CONFIG HELP FILE DIRECTORY VARIABLES --- url-prefix: "http://www.domain.dom/path/" directory-contents: read %./ ; --- GET LIST OF FILE NAMES WITH VALID EXTENSIONS FROM DIRECTORY --- file-list: copy [] for file-grab 1 (length? directory-contents) 1 [ file-name: first directory-contents file-ext: find/last file-name "." if file-ext = %.html [ append file-list file-name ] directory-contents: next directory-contents ] ; --- QUERY HELP FILES FOR KEYWORD --- pages-with-keyword: copy [] help-file-titles: copy [] foreach help-file file-list [ file-contents: read help-file if find file-contents cgi-input/keyword [ append pages-with-keyword help-file parse file-contents [thru <TITLE> copy text to </TITLE> (append help-file-titles text)] ] ] ; --- OUTPUT TO BROWSER --- print { <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <HTML> <HEAD> <TITLE>Title</TITLE> </HEAD> <BODY aLink=#3399ff bgColor=#ffffcc link=#0033cc text=#333333 vLink=#990000> <TABLE> <!-- begin search form --> <TR> <TD> <FONT color=#9a9a66 face="Times New Roman"><STRONG>Search</STRONG></FONT> <TR> <TD> <form method=get action="help_search.cgi"> <FONT FACE="'Times New Roman',Times,serif" SIZE="-1"><B>Search for :</b></font><BR><BR> <input type=text name="keyword"> <input type="submit" value="search"> </form> <!-- end search form --> <TR> <TD> <FONT color=#9a9a66 face="Times New Roman"><STRONG>Search Results</STRONG></FONT> <TR> <TD> <FONT FACE="'Times New Roman',Times,serif" SIZE="-1"><B>Click on a link to view information about your search word :</b></font><BR><BR> } for link-display 1 (length? pages-with-keyword) 1 [ page: first pages-with-keyword page-title: first help-file-titles print rejoin [{<TR>} {<TD>} {<A HREF="} url-prefix page {">} page- title {</A>} {<BR>}] pages-with-keyword: next pages-with-keyword help-file-titles: next help-file-titles ] print { </TABLE> </BODY> </HTML> }