On 29.06.2022 23:24, David Crayford wrote:
On 30/06/2022 4:22 am, Bernd Oppolzer wrote:

This is an old OS/2 REXX program (from the 1990s, IIRC),
used to traverse a directory tree recursively and issue a command in every 
subdirectory found:


/* rexx */

arg command

call RxFuncAdd "SysLoadFuncs", "REXXUTIL", "SysLoadFuncs"
call SysLoadFuncs

dir = directory()
if right(dir,1) = "\" then
   dir = left(dir, length(dir) - 1)

call tree dir, command

x = directory(dir)

exit


tree: procedure

   arg dir, command

   say "*** Verzeichnis in Bearbeitung: "dir" ***"

   x = directory(dir)

   command

   rc = SysFileTree("*.*", verz, "D")
   do i = 1 to verz.0
      dir = word(verz.i, 5)
      call tree dir, command
   end

   return


you may notice the recursive call of the procedure "tree".

I don't see any justification for your REXX bashing;
it's just another flavor of scripting language, which allows to do great things,
once you manage to use it.

Sorry Brend, but I don't consider that snippet to be great! It's a perfect example of flabby, verbose REXX code. The only justification for using REXX is that you personally favor the language. Python is far more succinct.

|for| |root, dirs, files ||in| |os.walk(path_of_the_directory):|
|||for| |i ||in| |files:|
|||print||(os.path.join(root, i))|

Just having to use those vertical bars to explicate how the Python code has to be formatted (indented) in order for it to work correctly is quite distorting.

Also the Python os module is quite extensive and hard to gain and keep an overview of the functionality it offers. [1]

---

Here a version of sysFileTree (also available in Regina's regutil package if not mistaken) that lists all files in all subdirectories:

   call sysFileTree "*.rex", "files.", "FSO"
   do i=1 to files.0
       say files.i
   end

Simple. REXX.

Here a version using ADDRESS...WITH and the operating system's dir command.

   cmd = "dir *.rex /b /s"
   ADDRESS SYSTEM cmd WITH OUTPUT STEM files.
   do i=1 to files.0
       say files.i
   end

Simple. REXX.

---rony

[1] "os — Miscellaneous operating system interfaces": 
<https://docs.python.org/3/library/os.html>

----------------------------------------------------------------------
For IBM-MAIN subscribe / signoff / archive access instructions,
send email to lists...@listserv.ua.edu with the message: INFO IBM-MAIN

Reply via email to