SpartaDOS X Reference Manual

Programming with SpartaDOS X




Open File

Index


Purpose To open a disk file for access through SpartaDOS X.
 
Syntax

OPEN #IOCB,aux1,aux2,"Dd:[path]fname.ext"
 

Remarks  

This command opens a disk file through SpartaDOS X. Aux1 is the mode (output, input, update, directory, etc.) in which the file will be opened. The following is a list of legal values for aux1. Unless otherwise noted, aux2 should be 0.

4 Open the file in read only mode.
 
6 Open a formatted directory. Provides a directory listing as do the DIR and DIRS commands from the command processor. Aux2 is used to determine the style of the directory. If aux2 is 0, standard DIRS format will be used. If aux2 is 128, the long DIR format, including size in bytes, date, and time, will be used.
 
8 Open the file in write only mode.
 
9 Open the file in append mode. Data will be written to the end of an existing file. If the file does not exist it will be created.
 
12 Open the file in update mode. This mode allows both reading from and writing to a file. Note: On a SpartaDOS format disk it is possible to position and/or write past the end of a file while in update mode.
An Example This short BASIC program will read the formatted directory of a disk in drive #1 in long format and print it to the screen:

    10 DIM ENTRY$(40)
    20 OPEN #1,6,128,"D1:*.*"
    30 REM The TRAP will cause the program to jump to line
    40 REM 80 when the end of the directory is reached.
    50 TRAP 80
    60 INPUT #1,ENTRY$:PRINT ENTRY$
    70 GOTO 60
    80 CLOSE #1

 

Accessing the Raw Directory Setting bit 4 of aux1 puts the OPEN in raw or unformatted directory mode. This allows you to read from and/or write to SpartaDOS directories as if they were normal data files. Although this is much faster than reading a formatted directory, there is no easier way to trash a disk and make it unusable than to make a mistake in the raw directory. Unless you feel confident about what you are doing and are using a disk you don't mind losing, stay away from the raw directories! This mode will work with Atari DOS disks if the ATARIDOS.SYS driver is installed. The driver translates the Atari directory format into SpartaDOS format and back.
 
Scan Mode Adding 64 to aux1 will place the OPEN in attribute scan mode. Aux2 is used to determine the attributes desired. If a long directory is wanted in scan mode, then 128 should be added to aux1 instead of to aux2.

To determine the file attributes to be scanned, the following values should be added to aux2, assuming an initial value of 0:

Protected add 1 Unprotected add 16
Hidden add 2 Not hidden add 32
Archived add 4 Not archived add 64
Subdirectory add 8 Not a subdirectory add 128

Only those files that fit the requested description will be referenced. A value of 0 in aux2 will ignore all attributes, even "Hidden".

For example, to get a long format directory of only the hidden files in the BASIC example on the previous page, simply substitute the following line:

    20 OPEN #1,6+64+128,2,"D1:*.*"

For a short directory listing without subdirectories, use

    20 OPEN #1,6+64,128,"D1:*.*"

and, finally, for a long listing of the unhidden, protected entries that end with a .COM extender, use

    20 OPEN #1,6+64+128,1+32,"D1:*.COM"

It is possible to select contradictory conditions (such as 1+16, protected and not protected) for each of the attributes. This will not produce an error but, since no directory entry can match both conditions, will always select no files.


Previous page

Next page