2
« on: February 25, 2025, 07:48:08 pm »
Sorry if I'm not doing this right. I am a very infrequent contributor and am still learning the ropes.
The code below is for anyone who wants to visit all directories, one by one, below the current directory
as root, out to the "leafs". It makes use of recursion inside a loop. It actually visits each directory
twice, once on the "head" recursion and again on the way back in, "tail" recursion.
It assumes RexxUtil.DLL HAS ALREADY BEEN LOADED. (I load it at boot time.)
You can find lots of nooks and crannies to put features in.
/* KERNEL CMD by Gord Snider v1.0 */
current = Strip( Directory(), 'T', '\') /* save fully qualified current directory for return */
SAY current /* say current directory */
CALL next current /* call to check for sub-directories */
EXIT 0
next: PROCEDURE /* hide old set of variables, enable new set */
PARSE ARG nextdir,spacer /* spacer is each line's indenting characters */
CALL SysFileTree Strip( nextdir, 'T', '\') || '\' || '*', 'dir.', 'DO' /* are subfolders here? */
DO dir = 1 TO dir.0 /* if any, make a list of them and process it */
IF dir < dir.0 THEN leader = D2C(195)
ELSE leader = D2C(192)
SAY spacer || ' ' || leader || SUBSTR( dir.dir, LASTPOS('\', dir.dir) + 1)
IF leader = D2C(195) THEN leader = D2C(179)
ELSE leader = ' '
CALL next dir.dir, spacer || ' ' || leader /* pivot point of the recursion */
END dir /* back to top of dir loop */
RETURN /* a leaf has been reached */