Search files using Turbo PascalTurbo Pascal (CP/M-80) provides the proceduresRESET(file) and REWRITE(file) for working with files
After execution, Turbo Pascal calls an internal error routine.
If an error occurs a message will be sent and the program is aborted.
The programmer may avoid abortion, if a file to be opened is not found, by using the directive {$I-}RESET(file){$I+} .
(But don't forget to handle a pending error e.g. by if IOresult<>0 then ... ).
This allows looking for a file, but with unambiguous file name only.
Sometimes, it is necessary to search for multiple files with ambiguous file name, e.g. search for files of type .TXT, which be represented in CP/M as *.TXT .
Mallard BASIC has a built in command − FIND$(name,number) − handling multiple files.
Here name means the mask for the files to be searched for and number is the number of the file to be fetched.
On success, FIND$ returns an unambiguous file name.
Otherwise, an empty string will be returned.
I will now describe a Turbo Pascal function which works the same way the Mallard BASIC function does.
The base for searching files are two BDOS functions, namely Search for First (function 17) and Search for Next (function 18).
Searching for first requires an CP/M File Control Block, subsequent calls to searching for next do not.
On success, the BDOS functions return a number in the range 0..3, otherwise 255.
The number is an index to one of four entries within the current DMA buffer.
Because the size of the buffer is 128 bytes, this results in a 32-byte file information − exactly one directory entry.
The first byte of this entry is the user area, followed by eight characters for the file name and three for the file extension.
The following CP/M structures are required for a file search:
Finds(name,number) is as follows:
Compiled by
Werner Cirsovius
|