strick@gatech.UUCP (08/13/84)
Here's a quick basic09 program to sort the files in a directory by name. Makes dirs more readable. Try it first on a disk with NOTHING important on it, because if either you or I make a mistake typing this in, it'll fry the directory. The program is not very efficient (uses StupidSort) but it does the job. It takes approx 40 seconds to sort 40 filenames. Empty slots are sorted to the bottom so new files added to the directory will show up at the bottom of the dir. strick ========================= PROCEDURE sortdir comments: TYPE dent = e(32) : BYTE dir entries are 32 bytes DIM d(100), t : dent up to 100 entries DIM p : BYTE DIM i : INTEGER PRINT "DIRECTORY SORTER" INPUT "Directory to sort > ", path$ OPEN #p, path$ : UPDATE + DIR PRINT "Directory open." I = 1 WHILE NOT( EOF(#p) ) DO GET #p, d(i) read in the dir file i = i + 1 ENDWHILE numrec = i - 1 PRINT numrec; " records" FOR d1=3 to numrec-1 very stupid bubble sort FOR d2=3 to numrec-1 x=d2 \ y=d2+1 x & y are inputs to sub500 GOSUB 500 compares entries IF z=1 THEN z is output from sub500 t=d(x) \ d(x)=d(y) \ d(y)=t swap entries ENDIF NEXT d2 print "."; NEXT d1 SEEK #p,0 rewind directory FOR i=1 to numrec PUT #p,d(i) write sorted dir out NEXT i CLOSE #p PRINT "done." END 500 REM comparison subroutine a dir entry is 29 bytes of name REM input x,y indexes to compare and 3 bytes of i-node. We will REM output z= if d(x)<d(y) then 0 treat it as 32 bytes all the REM else 1 same. IF d(x).e(1)=0 THEN empy slots start with 0 byte; z=0 \ RETURN \ ENDIF sort them to bottom. FOR i=1 to 32 pass thru names until a=d(x).e(i) \ b=d(y).e(i) you find a difference. IF a>127 THEN a=a-128 \ ENDIF IF b>127 THEN b=b-128 \ ENDIF EXITIF a<b THEN z=0 \ ENDEXIT right order -- dont swap EXITIF a>b THEN z=1 \ ENDEXIT wrong order -- must swap NEXT i RETURN ================================ -- Henry Strickland The Clouds Project, School of ICS, Georgia Tech, Atlanta GA 30332 CSNet: Strick @ GATech ARPA: Strick.GATech @ CSNet-Relay uucp: ...!{akgua,allegra,rlgvax,sb1,unmvax,ulysses,ut-sally}!gatech!strick