home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 18 REXX
/
18-REXX.zip
/
drtree.zip
/
DIRTREE.CMD
< prev
next >
Wrap
OS/2 REXX Batch file
|
1994-02-17
|
12KB
|
291 lines
/* DIRTREE R1.0 1/1/94 by Conrad W. Clark 70544,760 */
/* you are licensed to use, copy, and redistribute as long */
/* as the 1st 5 lines of this file remain as is, and you and */
/* subsequent licensees agree that this program is distributed */
/* as is, use and consequences are solely the responsibility of the user. */
/* rexx pgm to list dir or subdir structs */
/* [d:][path]dirtree[.cmd] filespec [sd|st|ss|sp|sn] [nod|not|nos|noa] */
/* for example at the E:> dirtree e:\rxtste\*.* */
/* optional arguments (in any order) to sort (major to minor) or shorten output */
/* sd - sort by file date nod - do not display date */
/* st - sort by file creation time not - do not display time */
/* ss - sort by file size nos - do not display size */
/* sp - sort by name including drive and path */
/* sn - sort by name excluding drive and path */
/* noa - do not display attributes*/
/* dirtree ? displays online help */
filespec = '' /* file specification to give to SysFileTree */
sorttype = '' /* type of sort, if any */
/* register rexx functions */
call RxFuncAdd 'SysLoadFuncs', 'RexxUtil', 'SysLoadFuncs' /* register all utility functions */
call SysLoadFuncs
/* get the structure to display or redirect - max 11 args */
arg filespec varg
if filespec = '' then
do
say 'ERROR, missing filespec. DIRTREE ? for help'
exit
end
starttime = time('R') /* reset elapsed timer */
if filespec = '?' then
do
say ' DIRTREE R1.0 1/1/94 by Conrad W. Clark 70544,760'
say ' a rexx program to list files including files in subdirectories.'
say ' '
say ' [d:][path]dirtree[.cmd] filespec [sd|st|ss|sp|sn] [nod|not|nos|noa]'
say ' for example at the E:> dirtree e:\rxtste\*.*'
say ' optional arguments (in any order) to sort (major to minor) or shorten output'
say ' sd - sort by file date nod - do not display date'
say ' st - sort by file creation time not - do not display time'
say ' ss - sort by file size nos - do not display size'
say ' sp - sort by name including noa - do not display attributes'
say ' and path'
say ' sn - sort by name excluding drive and path'
say ' '
exit
end
/* constants of valid arguments */
vcon = 'SD' 'ST' 'SS' 'SP' 'SN' 'NOD' 'NOT' 'NOS' 'NOA'
do i = 1 to words(varg) /* set up argument and constant arrays */
varg.i = word(varg,i)
end
do j = 1 to words(vcon)
vcon.j = word(vcon,j)
end
do i = 1 to words(varg) /* check arguments for validity */
foundflag = 0
do j = 1 to words(vcon)
if varg.i = vcon.j then
do
foundflag = 1 /* a valid argument */
leave j
end
end
if foundflag = 0 then /* not a valid argument */
do
say 'ERROR - invalid command line argument = ' varg.i
say 'DIRTREE ? for help '
exit
end
end
say 'filespec is' filespec
call SysFileTree filespec, 'files.', 'sf' /* get files in dir structure */
/* including subdirectories */
if result <> 0 then
do
say 'source file ERROR, SysFileTree result = ' result
say 'result 2 is not enough memory'
exit
end
if files.0 = 0
then
do
say 'no files found'
exit
end
sorttype.0 = 0
do isort = 1 to words(varg) /* get a sort(s) to do */
do jsort = 1 to 5
if varg.isort = vcon.jsort then
do
sortflag = 1 /* we will call sortfiles */
sorttype.0 = sorttype.0 + 1
sorttypeindex = sorttype.0
sorttype.sorttypeindex = varg.isort /* append another field to sort on */
say 'sort on ' varg.isort
end
end
end
if sortflag = 1 then call sortfiles /* sort if asked to */
/* sortfiles uses files., keysize, keyposition */
nodflag = 0
notflag = 0
nosflag = 0
noaflag = 0
do i = 1 to words(varg) /* see what to not print */
if varg.i = 'NOD' then nodflag = 1
if varg.i = 'NOT' then notflag = 1
if varg.i = 'NOS' then nosflag = 1
if varg.i = 'NOA' then noaflag = 1
end
do i = 1 to files.0 /* output each file */
outstring = ''
outstringptr = 1 /* current position in output */
/* move in stuff to display */
if nodflag = 0 then outstring = substr(files.i,1,10) /* insert date */
if notflag = 0 then outstring = outstring||substr(files.i,11,8) /* insert time */
if nosflag = 0 then outstring = outstring||substr(files.i,19,12) /* insert size */
if noaflag = 0 then outstring = outstring||substr(files.i,31,7) /* insert attributes */
outstring = outstring||substr(files.i,38) /* always display path||filename */
call lineout 'stdout:', outstring
if result <> 0 then
do
say 'source file ERROR, lineout result = ' result
say 'check 3rd argument, printer status, file name'
exit
end
end
starttime = time('E') /* running time */
say 'files found = ' files.0
say 'time to run dirtree = ' starttime
exit /* normal completion */
/**********************/
/* */
/* SORT ROUTINES */
/* */
/**********************/
sortfiles: /* shell sort of input files */
/* use shell sort (Sedgewick:Algorithms 1984) */
/* since many directories may be already ordered */
h = 1
do until h>files.0
h = 3*h+1
end
do forever until h = 1
h = h % 3 /* integer result */
do i = h+1 to files.0
v = files.i
j = i
k = j-h
/* assemble key1 */
key1 = ''
do sorttypeindex = 1 to sorttype.0
select /* get key1 in outer loop */
when sorttype.sorttypeindex = 'SD' then /* sort by date */
do
keysize = 8 /* mm/dd/yy is 8 bytes */
keyposition = 1 /* 1st field in files.i */
rawkey1 = substr(v,keyposition) /* blanks to 0 in key */
do ikey = 1 to keysize /* convert blanks to 0 */
if substr(rawkey1,ikey,1) = ' ' then rawkey1 = overlay('0',rawkey1,ikey)
end
/* reorder date in key */
key1 = key1||substr(rawkey1,7,2)||'/'||substr(rawkey1,1,3)||substr(rawkey1,4,2)
end
when sorttype.sorttypeindex = 'ST' then /* sort by time */
do
keysize = 6
keyposition = 11
rawkey1 = substr(v,keyposition)
do ikey = 1 to keysize /* convert blanks to 0 */
if substr(rawkey1,ikey,1) = ' ' then rawkey1 = overlay('0',rawkey1,ikey)
end
key1 = key1||rawkey1
end
when sorttype.sorttypeindex = 'SP' then /* sort by d:\path[\path..]\name.ext */
do
keyposition = 38
key1 = key1||substr(v,keyposition)
end
when sorttype.sorttypeindex = 'SN' then /* sort by name.ext */
do
key1position = lastpos('\',files.i) + 1 /* last \ is just before file name */
key1 = key1||substr(v,key1position)
end
when sorttype.sorttypeindex = 'SS' then /* sort by file size */
do
keysize = 10
keyposition = 19
rawkey1 = substr(v,keyposition,keysize)
do ikey = 1 to keysize /* convert blanks to 0 */
if substr(rawkey1,ikey,1) = ' ' then rawkey1 = overlay('0',rawkey1,ikey)
end
key1 = key1||rawkey1
end
otherwise
do
say 'ERROR in program logic sort key1' /* no sort argument */
say ' key1, sorttype.sorttypeindex = ' key1 sorttype.sorttypeindex '.' sorttypeindex
exit
end
end /* select */
end /* do sorttypeindex */
do forever
key2 = '' /* assemble key2 */
do sorttypeindex2 = 1 to sorttype.0
select /* get key1 in outer loop */
when sorttype.sorttypeindex2 = 'SD' then /* sort by date */
do
keysize = 8 /* mm/dd/yy is 8 bytes */
keyposition = 1 /* 1st field in files.i */
rawkey2 = substr(files.k,keyposition,keysize) /* blanks to 0 in key */
do ikey = 1 to keysize /* convert blanks to 0 */
if substr(rawkey2,ikey,1) = ' ' then rawkey2 = overlay('0',rawkey2,ikey)
end
/* reorder date in key */
key2 = key2||substr(rawkey2,7,2)||'/'||substr(rawkey2,1,3)||substr(rawkey2,4,2)
end
when sorttype.sorttypeindex2 = 'ST' then /* sort by time */
do
keysize = 6
keyposition = 11
rawkey2 = substr(files.k,keyposition,keysize)
do ikey = 1 to keysize /* convert blanks to 0 */
if substr(rawkey2,ikey,1) = ' ' then rawkey1 = overlay('0',rawkey1,ikey)
end
key2 = key2||rawkey2
end
when sorttype.sorttypeindex2 = 'SP' then /* sort by d:\path[\path..]\name.ext */
do
keyposition = 38
rawkey2 = substr(files.k,keyposition)
key2 = key2||substr(files.k,keyposition)
end
when sorttype.sorttypeindex2 = 'SN' then /* sort by name.ext */
do
key2position = lastpos('\',files.k) + 1 /* last \ is just before file name */
key2 = key2||substr(files.k,key2position)
end
when sorttype.sorttypeindex2 = 'SS' then /* sort by file size */
do
keysize = 10
keyposition = 19
rawkey2 = substr(files.k,keyposition,keysize)
do ikey = 1 to keysize /* convert blanks to 0 */
if substr(rawkey2,ikey,1) = ' ' then rawkey2 = overlay('0',rawkey2,ikey)
end
key2 = key2||rawkey2
end
otherwise
do
say 'ERROR in program logic sort key2' /* no sort argument */
say ' key2, sorttype.sorttypeindex2 = ' key2 sorttype.sorttypeindex2 '.' sorttypeindex2
exit
end
end /* select */
end /* do sorttypeindex2 */
if key2 <= key1 then leave /* ending condition */
files.j = files.k
j = j-h
k = j-h
if j <= h then leave
end /* inner do forever */
files.j = v
end /* do i = h1 to files.0 */
end /* do forever until h = 1 */
return
/* words subroutine */
/* call words(inputlist) returns number of words in inputlist */
iwords = 0
do while word(inputlist,iwords) <> ''
iwords = iwords + 1
end /* do */
return iwords