home *** CD-ROM | disk | FTP | other *** search
- :: FINDREAD.BTM
- :: Purpose: to find a file on disk, including compressed in a ZIP archive,
- :: and read it immediately. See HELP below for details.
- :: (Itamar Even-Zohar, May 12, 1994)
-
- if %@index[%1,h] ge 0 .and. %@index[%1,h] lt 2 goto help
- if .%1==. goto help
-
- setlocal
-
- :check_pgms
- set editor=t.com
- set num=0
- if not exist %@search[t.com] (set pgm=t.com^gosub error)
- if not exist %@search[whereis.exe] (set pgm=whereis.exe^gosub error)
- if not exist %@search[pkunzip.exe] (set pgm=pkunzip.exe^gosub error)
- if .%finished==.yes goto quit
-
- call settemp
- :: ('settemp.btm' is a batch file which defines a temporary drive/path.)
- set fn=%temp%finds
- set flog=%temp%findread.log
-
- :repeat
- :: (check what was last query.)
- iff exist %flog then
- set lines=%@lines[%flog]
- set src_string=%@line[%flog,%lines]
- endiff
-
- iff .%1==./log then
- iff not exist %flog then
- echo %@upper[%@filename["%flog"]] not found
- goto quit
- endiff
- *list %flog
- goto quit
- endiff
-
- :search
- iff .%src_string==.%1 .and. exist %fn then
- goto select
- :: (use results file again if search item is identical to
- :: last query and the log file exists.)
- else
- whereis %1 -a >%fn
- :: (collect all search results to file "finds" on temporary
- :: drive)
- keystack 0 ALT-D ALT-D ALT-D ALT-X
- t %fn
- :: (delete 3 first lines from top of file using Gil's T.COM)
- echo %1 >>%flog
- :: (create, or append, search string to the log file, "findread.log",
- :: on temporary drive.)
- cls
- endiff
-
- :select
- set cmdline=%@select[%fn,1,8,24,80, %& files ]
- if "%cmdline"=="" goto quit
-
- iff %@index[%cmdline,(] eq 0 then
- set from=%@eval[%@index[%cmdline,(]+1]
- set to=%@eval[%@index[%cmdline,)]-1]
- set src_file=%@substr[%cmdline,%from,%to]
- gosub remove_space
- goto ext&read
- else
- goto reg_file
- endiff
-
- :ext&read
- set arc_file=%@substr[%cmdline,41]
- :: (You may replace 'pkunzip' and 4DOS "list" by UNZIP
- :: and /or Buerg's LIST.)
- ::pkunzip -c %arc_file %src_file |list /s
- ::unzip -p %arc_file %src_file |list /s
- pkunzip -c %arc_file %src_file |*list /s
- goto quit
-
- :reg_file
- set src_file=%@substr[%cmdline,0,13]
- gosub remove_space
-
- :read_reg
- set pathf=%@substr[%cmdline,41]
- *list %pathf%%src_file
- goto quit
-
- :quit
- if exist %fn.bak del /q %fn.bak
- endlocal
- quit
-
- ::-------------------HELP------------------------
- :help
- cls
- screen 1 0
- text
- FINDREAD.BTM
- Searches disk for a given string, displays results, and allow quick reading
- of desired file, whether temporarily extracted from a ZIP archive, or as a
- plain text file.
- You can read consecutive files for the same query by running the batch
- again after it first created results file. As long as you do not enter a
- new query, the same results file will be used.
- If you wish to check your queries for last session, type FINDREAD /log
-
- SYNTAX:
- FINDREAD {string|"string"} or /h (for HELP), or /log (for log of queries)
- where string (without inverted commas) can contain wildcards.
- A string between inverted commas is a "regular expression": it
- represents any segment from a filename.
-
- Examples:
- FINDREAD finda*.*
- or
- FINDREAD "finda"
-
- Note: This batch requires Ledbetter's filefinder SST.EXE (renamed back
- to WHEREIS.EXE), Katz's PKUNZIP (or UNZIP), and Gil's T.COM, all of which
- are downloadable from Simtel20 mirror sites.
- endtext
- quit
- ::---------------subroutines---------------------
- :remove_space
- :: (remove blank spaces between filename and extension
- :: if it exists.)
- set dot=%@char[46]
- set dot_pos=%@index[%src_file,%dot]
- iff %dot_pos gt 0 .and. %dot_pos lt 12 then
- set fil1=%@trim[%@substr[%src_file,0,%dot_pos]]
- set fil2=%@substr[%src_file,%dot_pos]
- set src_file=%fil1%%fil2
- else
- set src_file=%@substr[%src_file,0,9]
- set src_file=%@trim[%src_file]
- endiff
- return
-
- :error
- set num=%@eval[%num+1]
- beep
- echo "%@upper[%pgm]" not found. Can't run FINDREAD.BTM
- if %num ge 1 set finished=yes
- return
-