Post Reply 
(48) SORTDIR, SORTALL
05-15-2014, 06:19 PM
Post: #1
(48) SORTDIR, SORTALL
A couple more 48 tools. To run these on an S/SX, you'll need to install replacements for DOLIST and SORT.

These two programs automate alphabetizing your variables, either for a single directory, or the entire directory tree (or just a subset of it). Both programs are commented and include headers for ASCII transfer if you want to load them that way, but they're both short enough to key in as well.

On my 48GX, which is only modestly loaded with junk, the whole process takes a couple minutes to run (mostly because the ORDER command seems to be very slow).

SORTALL

This program recursively calls itself in every subdirectory beginning with the current directory (depth-first), then runs SORTDIR to sort the variable list as it passes through each directory. So if you run it from within HOME, you'll generally get a fully sorted directory tree. (I say generally, because it doesn't touch the hidden directory, and you can customize the sorting behavior per directory.)

You'll probably want to store this in HOME so it can be called everywhere.

Input: None (just switch to the correct directory first)
Output: None (some status messages are displayed while executing)

Code:
%%HP: T(3)A(D)F(.);
\<<
@ Get subdirectories in the current directory.
  15 TVARS
@ Any to sort?
  IF DUP SIZE
  THEN
@ Recurse into each subdirectory,
@ and run SORTALL again.
    1 \<< EVAL SORTALL \>> DOLIST
  ELSE
@ Drop the empty subdirs list.
    DROP
  END
@ Display the current path about to be sorted.
  PATH 2 DISP
@ Launch SORTDIR to do the sort, then go back up.
  SORTDIR UPDIR
\>>

SORTDIR

This program does the actual sorting, and should be stored in HOME. You can customize the sorting behavior beneath any specific directory by creating a new SORTDIR within any directory. If you create a custom version, it must run with no stack inputs, and should avoid leaving any stack output to prevent weird DOLIST artifacts.

The default version given here sorts variables with directories listed first alphabetically, followed by programs listed alphabetically. The remaining variables are left unsorted at the end of the list to reduce run time.

Input: None (switch to the desired directory first)
Output: None (status messages will be displayed while running)

Code:
%%HP: T(3)A(D)F(.);
\<<
@ Get/sort programs in the current directory.
  8 TVARS
  IF DUP SIZE
  THEN
    "Sorting programs" 1 DISP
    SORT
    "Updating programs" 1 DISP
    ORDER
  ELSE
@ Drop the empty program list.
    DROP
  END
@ Get/sort subdirectories in the current directory.
  15 TVARS
  IF DUP SIZE
  THEN
    "Sorting directories" 1 DISP
    SORT
    "Updating directories" 1 DISP
    ORDER
  ELSE
@ Drop the empty dir list.
    DROP
  END
@ Clear the status message.
  "" 1 DISP
\>>
Visit this user's website Find all posts by this user
Quote this message in a reply
Post Reply 




User(s) browsing this thread: