Richard C. Wilson
"Filetracker" for VIC or Commodore 64 solves those irritating problems that arise so often, when you can't remember if the file you want is on the disk you're working with, or you can't remember how you spelled the filename. By using Filetracker as a subroutine, you can look up any filename and read or write it while your main program is running.
Other possible uses for Filetracker include crosschecking filenames, generating filenames, compiling a disk library cross-reference index, computing disk space remaining, reformatting directory output to screen or printer, and autorun of programs. See the "Automatic Proofreader" article on page 60 before typing in this program.
Sequential files are very useful tools for storage and retrieval of long data lists on disk. One problem arises occasionally, however: How do you read a sequential file when you don't know its name? The simple answer, of course, is to stop the program, read the disk directory, memorize or write down the filename, then run the program again and enter the correct filename.
This method is less painful if you are using a DOS wedge that allows you to read the disk directory without erasing the program in memory. But it's not very helpful if you are trying to merge data from several related files into a new file, and you must stop repeatedly to look up filenames.
Let The Computer Do It
You can save yourself time and aggravation if you have your computer look up the names on the disk and read the appropriate files. This can be especially useful with a business program which stores each order and account in a separate sequential file. If the account filename is the last four digits of the client's phone number, when an order is written, the account file is read, the account number is added to the order number, and the combined (hyphenated) number becomes the name of the new file. For example, order number 1666 from client 1212 becomes file 1666-1212.
Once the disk starts to fill up (it will hold over 100 such files), sorting out just those order files assigned to account number 1212 can be quite tiresome. "Filetracker" solves such problems.
Selecting The Files You Want
Lines 20-120 read the disk directory. Line 120 prints the number of blocks, name, and file type for each file. (You can delete this line if you don't want to display the entire disk directory.)
The name (only) of each file is stored in the 1$ array. Line 150 selects out names of all sequential files and discards the rest. By changing SEQ in this line to PRG, REL, or USR, you can have the line look exclusively for any type of file.
For example, instead of having line 150 return to get another filename when the condition is not met, it could go to one or more secondary routines to create separate arrays for other file types.
Lines 60 and 130 check the Status word to make certain the disk channel is closed. The program ends when there is no more data to be read.
Making It A Subroutine
To use Filetracker in other programs, change the END statement in line 140 to a RETURN, and the program becomes a subroutine.
If you use Filetracker as a subroutine, then the main program should ask for a key word (1212) which would be assigned to a variable (KY$).
Since all the filenames are structured the same way, we can change line 150 to compare KY$ with the account number portion of each sequential filename.
150 IF RIGHT$(I$(P),4)<>KY$ THEN I$(P) = "" :GOTO30
If line 120 is left in the routine, all the files listed in the disk directory will be printed on the screen, and the 1$ array will contain the names of all (and only) the order files assigned to account number 1212.
You also can write a subroutine to read each of the files into a two- or three-dimensional array, for further processing.
An Array For Each File Type
By adding these lines to Filetracker, you can enter the names of each type of file into a separate array.
150 IFLEFT$(N$,3)<>"SEQ"THEN152 151 P = P+1 : GOTO30 152 IFLEFT$(N$,3)<>"PRG"THEN154 153 P$(K) = I$(P) : I$(P)="" : K = K+1 : GOTO30 154 IFLEFT?(N$,3)<>"REL"THEN156 155 R$(L) = 1 $(P) : I $(P) = " " :L = L+1:GOTO30 156 IFLEFT$(N$,3)o"USR"THENI$(P)+"":GOTO 30 157 U$(M)=1$(P) : I$(P)="":M = M+1:GOTO30
Notice that line 150 is modified to branch to line 152, and you will have to DIMension any arrays you introduce into the program.
5 DIMI$(151) :rem 100 10 PRINT"READING SEQUENTIAL FILES…" :rem 36 20 P=0:OPEN3, 8, 0 "$0":GET#3,D1$,D2$ :rem 61 30 GET#3,Dl$,D2$:GET#3,Dl$,D2$:N=0 :rem 20 40 IFDl$o""THENN=ASC(Dl$) :rem 197 50 IFD2$o""THENN=N+ASC(D2$)*256 :rem 8 60 GET#3,D2$:IFST<>0THEN140 :rem 64 70 IFD2$<>CHR$(34)THEN60 :rem 88 80 GET#3,D2$:IFD2$<>CHR$(34)THENI$(P)=I$( P)+D2$:GOTO80 :rem 34 90 GET#3,D2$:IFD2$=CHR$(32)THEN90 :rem 84 100 N$="" :rem 132 110 N$=N?+D2$:GET#3,D2$:IFD2$ <>""THEN110 :rem 144 120 PRINTN;" ";I$(P),N$ :rem 212 130 IFST=0THEN150 :rem 252 140 CL0SE3:END :rem 79 150 IFLEFT$(N$,3)<>"SEQ"THENI$(P) = "" :GOTO 30 :rem 209 160 P=P+1:GOTO30 :rem 166