Marked as: Normal
Hi all,
This time I've created a script to search files for text. First you type the name of the script and then what to search for e.g.
"myfindstr *.txt" and it's ask you for the text to find there, e.g. "computer".
When it has listed files, it will ask you to enter yet another criteria to limit the search futher e.g. "message", and it'll look for that and only display text with that combination present.
The code contain alot of the functions I've used elsewhere and may therefore appear to contain alot of extra "weight", of some that you may find is not needed. It's very convenient to create functions that one can reuse
/**/
@Echo Off
@cls
say ''
call Trace 'O'
cfg.debug = 0
cfg.curr_time = TIME( 'R' )
If RxLoadLib( 'SysStemSort', 'SysLoadFuncs', 'RexxUtil' ) Then
Exit 1
call RxOut 0, 'Search for:'
call SysCurPos 0, 11
PARSE PULL instring
call SysFileTree ARG(1), 'file.', 'SFO' /* Remove/Rewrite to not contain S (in SFO) to only search 1 folder. */
DO i = 1 TO file.0
rc = SysFileSearch( instring, file.i, 'outstring.i.', 'n' )
call rxMeter 3, i / file.0, 1
call rxWorking 5, outstring.i.0||' occurances of "'||instring||'" in '||file.i
END
call RxOut 1, 'Search in results for:'
call SysCurPos 1, 24
PARSE PULL instring
call SysCurPos 6, 0
DO i = 1 TO file.0
if rc = 0 & outstring.i.0 > 0 then
do
contains = 0
do j = 1 to outstring.i.0
if POS( translate( instring ), translate( outstring.i.j ) ) > 0 | instring = '' then do
if contains = 0 THEN
do
say FILESPEC( 'N', file.i )||' contain: '
contains = 1
end
say outstring.i.j
say ''
END
end
end
END
Return 0
RxLoadLib: Procedure Expose !REXXDW. cfg.
If RxFuncQuery( ARG(1) ) \= 0 Then
If RxFuncAdd( ARG(2), ARG(3), ARG(2) ) \= 0 Then
Return 1
interpret 'If '||ARG(2)||'() \= 0 Then Return 1'
Return 0
rxWorking: Procedure Expose cfg.
if cfg.debug | TRACE() = '?I' THEN Return 0
if cfg.curr_time + 1 < TIME( 'S' ) then do
SELECT
WHEN cfg.counter = 1 THEN
call rxOut ARG(1), left( '/ '||ARG(2), 80 )
WHEN cfg.counter = 2 THEN
call rxOut ARG(1), left( 'Ä '||ARG(2), 80 )
WHEN cfg.counter = 3 THEN
call rxOut ARG(1), left( '\ '||ARG(2), 80 )
OTHERWISE
cfg.counter = 0
call rxOut ARG(1), left( '³ '||ARG(2), 80 )
END
cfg.counter = cfg.counter + 1
cfg.ok = 1
cfg.curr_time = TIME( 'S' )
end
Return 0
rxMeter: Procedure Expose cfg.
if cfg.debug | TRACE() = '?I' THEN Return 0
temp = 100 * ARG(2)
if length( format( temp,, 0, 0 ) ) > 3 then
Return 0
temp = format( temp, 3, 0, 0 )
if cfg.progress <> temp | cfg.ok = 1 then do
processed = FORMAT( min( 76 * ARG(2), 76 ),, 0, 0 )
if datatype( ARG(3), 'N' ) then do
loaded = FORMAT( min( 76 * ARG(3), 76 ),, 0, 0 )
if temp > ARG(3) * 100 then
temp = format( 100 * ARG(3), 3, 0, 0 )
end
else loaded = 0
total = copies( '░', 76 - max( loaded, processed ) )
if processed > loaded then do
len = loaded
loaded = copies( '▒', max( processed - loaded, 0 ) )
processed = copies( '█', max( len, 0 ) )
end
else do
loaded = copies( '▒', max( loaded - processed, 0 ) )
processed = copies( '█', processed )
end
call rxOut ARG(1), left( processed||loaded||total, 76 )||right( min( temp, 100 ), 3 )||'%'
cfg.progress = temp
cfg.ok = 0
end
Return 0
rxTimeOut: Procedure Expose cfg.
if cfg.ok = 1 then
call RxOut ARG(1), ARG(2)
Return 0
rxOut: procedure
if datatype( ARG(1), 'W' ) then
parse value SysCurPos( ARG(1), 0 ) with prev_row prev_col
say left( ARG(2), max( 80, min( length( ARG(2) ), 80 ) ) )
if datatype( ARG(1), 'W' ) then
call SysCurPos prev_row, prev_col
Return 0
//Jan-Erik