Commodore Disk Pattern Matching
Jim Butterfield, Associate Editor
Last month we looked at some of the features of pattern matching. Now let's see how to deal with those annoying comma files.
Most disk users who do a little programming end up with one or more files on disk with an odd name: a comma. The files seem to be good, but the name makes them impossible to handle: It seems that you can't open or scratch such a file since attempting to use such a name always gives a syntax error response.
Such files seem so inaccessible that many users start to wonder how they managed to create them in the first place. Any attempt to create them deliberately usually ends up in the same syntax error message.
Just in case you've never seen one, or wonder how they happen, the following program has a bug which will cause a comma file to be created. You may want to try it.
100 INPUT "NAME OF FILE";N$ 110 OPEN 1,8,3, + F$ + ", S, W" 120 FOR J = l TO 50 130 PRINT #1, SQR (J) 140 NEXT J 150 CLOSE 1
The above program puts 50 square root values on a file. The user is asked to give a filename, which becomes the string variable N$. The program then opens a sequential file for writing, but there's an oops: We mistakenly use variable F$ for the filename instead of N$. F$ contains nothing; so we create a "no name" file—our open name file string ends up as "0:,S,W". The disk opens the file, but can't find a name; so it uses the first character it sees where the name should be: the comma.
The same thing could happen on a Commodore 64 or VIC even if the program were correct, with N$ instead of F$ in line 110. If the user pressed the RETURN key instead of typing in a filename, N$ would contain nothing—it would be a "null string," and the same comma file would be written. By contrast, a "nothing" input on a PET/CBM would cause the program to stop and the file wouldn't be written.
Oddly, you can have more than one comma file on a disk. You won't get a FILE EXISTS message.
Scratching Comma Files
If your disk has one or more comma files and you just want to get rid of them, the job is fairly easy. Use pattern matching to find out how many files you have with one-character names. Type:
or, with the DOS wedge:
and you'll see all the one-character names, including all the comma files.
If you have any files other than the comma ones with one-character names, change their names using the RENAME command. For example, if you have a file named X, you could temporarily change it to X99. After the comma files are gone, you can change the name back again. To change name X to X99, type:
OPEN 15,8,15 PRINT # 15,"R0 : X99 = 0 : X" CLOSE 15
or, with the DOS wedge:
@R0 : X99 = 0 : X
Now, take the same directory command as before to get a new list of the files with single-character names. If you've correctly renamed the legitimate files, you'll get only the comma files. If you have missed any, go back and rename them. When you are sure that the only one-character names belong to comma files, get rid of them with the Scratch command. Type:
OPEN 15,8,15 PRINT #15, "S0:?" CLOSE 15
or, with the DOS wedge:
One command scratches all the files. The job is done.
It would be nice if we could rename files using the same pattern-matching system. Sometimes the data on a file is of value, and we'd like to reclaim it. Providing we need only the first comma file, we can usually get the information back.
We follow the previous procedure of insuring that the comma program is the only single-character name on the disk. If it's a program (and this is rare), we can usually get it with LOAD "?",8 followed by a save with an appropriate name. If it's a sequential file (by far the most common situation), we must write a small program to read the data.
If we just want to read the data, and not copy it to a new file, the following simple program will work with most files:
100 OPEN 1, 8, 2, "0 : ?, S, R" 120 INPUT #1, A$ 140 PRINT A$ 160 IF ST = 0 GOTO 120 180 CLOSE 1
If we want to copy the data to a new file, the above program needs to be expanded a little:
100 OPEN 1, 8, 3, "0: ?, S, R" 110 OPEN 2, 8, 4, "0: RECLAIM, S, W" 120 INPUT#1,A$ 130 SW=ST 140 PRINT A$ 150 PRINT#2,A$ 160 IF SW=0 GOTO 120 170 CLOSE 2 180 CLOSE 1
As you can see, we're still using pattern matching to get the data. If your file is more complex, you may still use the same techniques to go after the information. Line 110 has named the new file RECLAIM; you may of course give it any name you like.
Pattern matching is useful for a variety of disk tasks. It's almost indispensable for dealing with the comma file.
Comma files are caused by programming or user mistakes. Get after them quickly, since you might be able to reclaim information written there. And, of course, look to the cause of these files—something needs fixing.