home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 18 REXX
/
18-REXX.zip
/
rexxlb.zip
/
SAMPLES
/
TREED.CMD
< prev
next >
Wrap
OS/2 REXX Batch file
|
1993-01-09
|
3KB
|
95 lines
/*****************************************************************************/
/* */
/* TREED: diagrams tree structure of a disk with subdirectories. Starts at */
/* root directory of current disk, or at directory given as argument. */
/* */
/* Requires Personal REXX or REXXLIB (dosdrive, doscd, dosdir, arraysort */
/* functions). */
/* */
/* Command format: TREED <directory> */
/* */
/*****************************************************************************/
/* process parameter, if any, and check it names existing directory */
base = strip(arg(1))
name.0 = base
location.0 = 1
if right(base,1) = '\' then
base = left(base, length(base)-1)
if base = '' then
base = dosdrive()':'
badarg = 0
if length(base) = 2 & right(base, 1) = ':' then do
if doscd(base) = '' then badarg = 1
end
else do
if dosdir(base,,'d','d') = '' then
badarg = 1
end
if badarg then
say "'"arg(1)"'" 'is not the name of a directory.'
else
call tree base, 1 /* call tree routine to do the real work */
exit
/* subroutine to recursively trace through directory tree structure */
tree: procedure expose name. location. total.
arg directory, depth
n = 0
name = dosdir(directory'\*.*','n','d','d')
do while name \= ''
if name \= '.' & name \= '..' then do
n = n + 1
dir.n = name
end
name = dosdir(,'n','d','d')
end
call sortdir n
total.depth = n
do loc = 1 to n
name.depth = dir.loc
location.depth = loc
call tree directory'\'dir.loc, depth+1
call output
end
return
/* routine to output a line of the output diagram */
output:
if name.depth = '' then return
line = ''
do i = 1 to depth
select
when i < depth & name.i = '' then
if location.i = total.i then
join = ''
else
join = d2c(179)
when total.i = 1 & name.i \= '' then join = d2c(196)
when location.i = 1 then join = d2c(194)
when location.i = total.i then join = d2c(192)
otherwise join = d2c(195)
end
line = left(line,(i-1)*11) || join
if name.i \= '' then do
line = left(line,(i-1)*11) || join || d2c(196) || name.i
if i < depth then
line = left(line,i*11,d2c(196))
end
name.i = ''
end
if location.0 = 1 then do
say name.0 || d2c(196) || line
location.0 = 0
end
else
say copies(' ',length(name.0)+1) || line
return
/* sort a list of subdirectories into alphabetical order */
sortdir: procedure expose dir.
parse arg n
if n > 0 then
call arraysort 'dir.', 1, n, 1, 256, 'a'
return