Post Reply 
Summing lists in directory structure
09-15-2017, 05:49 PM
Post: #4
RE: Summing lists in directory structure
Here's an additional example of one way to approach this.

As written, the following RPL program needs to be saved in the root of your HOME directory (or in a library) so that it can be accessed appropriately. It could be saved somewhere else if you make a minor change to it, though I'll leave that as an exercise for the reader. Smile

Code:
DODIRS
\<<
  \-> prog      @ save the program given as an argument in a local variable
  \<<
    prog EVAL   @ execute the program in the current directory
    15 TVARS    @ obtain a list of any subdirectories in the current directory
    IF { } OVER SAME NOT THEN             @ if any subdirectories exist...
      1 \<< EVAL prog DODIRS \>> DOSUBS   @ execute DODIRS on all of them
    ELSE        @ else there weren't any subdirectories
      DROP      @ drop the empty list; nothing further to process
    END
  \>>
\>>

DODIRS takes another RPL program in stack level 1 as an argument, then executes it in the current directory and each "child" subdirectory to the current one.

As an example, let's say that you wanted to obtain a list of all of the directories currently defined in your directory tree. You can do this simply by setting HOME as your current directory, then passing a simple program to DODIRS which updates a result list as the directory tree is traversed:

Code:
TestDODIRS
\<<
  {} PATH \-> result cd
  \<<
    HOME
    \<<
      PATH 1 \->LIST 'result' SWAP STO+
    \>>
    DODIRS
    result
    cd EVAL
  \>>
\>>

Hopefully the combination of Pier's and these examples will spark some ideas for you.
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
RE: Summing lists in directory structure - DavidM - 09-15-2017 05:49 PM



User(s) browsing this thread: 1 Guest(s)