home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 18 REXX
/
18-REXX.zip
/
rexxlb.zip
/
SAMPLES
/
LSDIR.CMD
< prev
next >
Wrap
OS/2 REXX Batch file
|
1993-01-08
|
4KB
|
98 lines
/*****************************************************************************/
/* LSDIR: Show directory structure, with file counts and space totals */
/* */
/* The purpose of the following REXX program is to list all subdirectories */
/* in a tree, together with the number of files each contains and the */
/* amount of disk space consumed by the files. If the directory has */
/* subdirectories, the cumulative totals for files and space in all */
/* subdirectories is also shown. Apart from any utility this program may */
/* have, it illustrates one way of representing tree structures in REXX. */
/* Specifically, a unique identifier analogous to a library dewey decimal */
/* is constructed for each subdirectory (tree node) as it is encountered. */
/* This identifier is then used as one part of a compound name that */
/* references various quantities associated with each node. */
/* */
/* Requires Personal REXX or REXXLIB (doscd, cursor, parsefn, dosdrive, */
/* dosdisk, dosdir, dosdirpos, scrput functions). */
/* */
/* Command format: LSDIR <directory> */
/* */
/*****************************************************************************/
arg dir .
if dir = '' then
dir = doscd()
parse value cursor() with row col
col = 1
disk = word(parsefn(dir),1)
if disk = '-' then
disk = dosdrive()
sectors = dosdisk('s',disk)
round = sectors * 512
tree. = 0
tree..dirs = 1
tree..name = 'top'
prefix = ''
call bldtree dir, prefix
call scrput row, col, copies(' ',80)
call showtree '', 0, 1
return
/* build the data structure */
bldtree: procedure expose tree. row col round
arg dir, prefix
path = prefix'.'tree.prefix.dirs
tree.path.dirs = 0
tree.path.files = 0
tree.path.bytes = 0
tree.path.name = dir
tree.path.totfiles = 0
tree.path.totbytes = 0
call scrput row, col, left('Reading:' dir,80)
if word(parsefn(dir),2) \= '\' then
dir = dir||'\'
line = dosdir(dir'*.*','san','hsd')
do while line \= ''
position = dosdirpos();
parse var line size attr name
if name \= '.' & name \= '..' then
if pos('D',attr) \= 0 then do
tree.path.dirs = tree.path.dirs + 1
call bldtree dir||name, path
end
else do
tree.path.files = tree.path.files + 1
size = ((size + round - 1) % round) * round
tree.path.bytes = tree.path.bytes + size
end
line = dosdir(,'san','hsd',,position)
end
tree.path.totfiles = tree.path.totfiles + tree.path.files
tree.path.totbytes = tree.path.totbytes + tree.path.bytes
tree.prefix.totfiles = tree.prefix.totfiles + tree.path.totfiles
tree.prefix.totbytes = tree.prefix.totbytes + tree.path.totbytes
return
/* display the tree */
showtree: procedure expose tree.
arg prefix, level, number
path = prefix'.'number
if level = 0 then
name = tree.path.name
else do
i = lastpos('\',tree.path.name)
name = left(substr(tree.path.name,i+1),8)
end
size = (tree.path.bytes + 1023) % 1024
totsize = (tree.path.totbytes + 1023) % 1024
line = copies(' ',level)||name right(tree.path.files,3) right(size||'K',6)
if tree.path.dirs \= 0 then
line = line right(tree.path.totfiles,5) right(totsize||'K',6)
say line
do i = 1 to tree.path.dirs
call showtree path, level+1, i
end
return