HP Forums

Full Version: A useful HP-50G program to keep the DIRs clean...
You're currently viewing a stripped down version of our content. View the full version with proper formatting.

Everyone has their personal preferences for organizing their homes, rooms, offices, etc. - even the directories and files on personal computers. I am a neat freak and like things to be highly organized. The way in which the directories and objects on my HP-50G are organized makes it easy for me to locate important things.

I like every directory from HOME on down to be organized like this: alphabetically with directories first and all other objects afterwards.

I like programs to clean up after they are run by making sure that the flags are restored to their pre-run state and I want the VAR menu to always be displayed.

I'm also an automation freak. On my Linux workstations, I have a collection of useful scripts that I wrote that make working with the system very easy. Likewise so for my HP-50G, I have written a series of useful programs that keep things organized the way I like them.

Here is a program I wrote (that resides in HOME) to relist all directories and objects to my liking. I'm posting it here so others may find usefulness with it too...

<<
"Relisting the Directory..." 1. DISP
{} DUP 'xA' STO 'xB' STO
VARS OBJ-> 1. SWAP
START
DUP 1. ->LIST SWAP VTYPE
IF 15. ==
THEN xA + 'xA' STO
ELSE xB + 'xB' STO
END
NEXT
xA SORT xB SORT + ORDER
{xA xB} PURGE 2. MENU
>>
'ReList' STO

I have it in the HOME's CST list, so it can run in any subdirectory and clean up whatever is the "current" directory.

P.S. Nobody is perfect, so I welcome suggestions for improvement.

Edited: 12 Nov 2009, 2:20 p.m.

I use a very similar program on my 48GX. It's actually multiple programs - one of them to do the actual sorting, and one to recursively traverse the whole directory structure.

SORTALL: This is the program that sorts all directories beneath the current directory. It works by stepping through each directory in the current directory, and then running itself from within those directories. After that, it sorts the current directory, and goes back up one level. Run it in HOME to sort everything (except the hidden directory).

<< 0 { } \-> P DIRS
<< 15 TVARS 'DIRS'
STO DIRS SIZE
IF
THEN 1 DIRS
SIZE
FOR P DIRS P
GET EVAL SORTALL
NEXT
END PATH 1 DISP
SORTDIR UPDIR
>>
>>

SORTDIR: This is the program that actually does the sorting. The main version lives in HOME, and sorts into an alphabetical list of directories, followed by programs, followed by everything else. The "everything else" isn't alphabetized, to save time.

<< 8 TVARS DUP
IF SIZE 1 >=
THEN SORT ORDER
ELSE DROP
END 15 TVARS DUP
IF SIZE 1 >=
THEN SORT ORDER
ELSE DROP
END
>>

The reason this is a separate program is because I have a different version of SORTDIR stored in some directories where I want special sorting rules. For example, I have a directory with some custom units, and a CST menu. I hide all the actual unit variables by sorting them after an object with a null name, since CST provides better functionality than VAR does for unit menus, where it's rather easy to accidentally overwrite them. Then I have another directory where I only sort a couple program names to the front, and leave everything else as-is.

Quote:
[...]

<<
"Relisting the Directory..." 1. DISP
{} DUP 'xA' STO 'xB' STO
VARS OBJ-> 1. SWAP
START
DUP 1. ->LIST SWAP VTYPE
IF 15. ==
THEN xA + 'xA' STO
ELSE xB + 'xB' STO
END
NEXT
xA SORT xB SORT + ORDER
{xA xB} PURGE 2. MENU
>>
'ReList' STO

P.S. Nobody is perfect, so I welcome suggestions for improvement.


Bill,

You can replace "xA + 'xA' STO" with "'xA' STO+"

On the non-programming side, here's a trick for sorting things when the sort order isn't alphabetic. Prefix the name with a number. For example, sometimes I need one subdirectory for each month, so I call them 01Jan 02Feb 03Mar etc.

Thanks for sharing this utility.

Dave

You're welcome, Dave - and thanks for improving it! :)

Thanks Dave! I have Droid48 on my T-Mobile G1 cell-phone, so I'll add your code to the emulator and see how it works out. :)