home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
POINT Software Programming
/
PPROG1.ISO
/
basic
/
qlib
/
disk.doc
< prev
next >
Wrap
Text File
|
1993-10-11
|
30KB
|
831 lines
DISK / FILE routines look for specified files on your disk, or report
disk status. Several QLIB disk/file subroutines return the following
error codes:
1 = file name is a nul string
2 = file not found
3 = path not found
4 = too many open files
5 = access denied (file may be read-only or a subdirectory,
or subdirectory not empty)
6 = handle invalid
8 = insufficient memory
15 = invalid drive
19 = disk is write-protected
&HFFFF = input past end of file
File attributes may be combined. Each bit of a file attribute means:
0 = normal files
1 = read-only
2 = hidden files
4 = system files
8 = volume label (only one per disk - may not be
reliable)
16 = subdirectories
32 = archive bit set
Thus a file attribute of 18 is a hidden subdirectory (16 OR 2)
Note that QLIB subroutines no longer require zero-terminated filenames.
QLIB's Input/Output subroutines provide fast, flexible file handling,
replacing BASIC's clumsy functions. These subroutines return an error
code in QLIB's DOSError flag if something went wrong.
Summary of QLIB's file I/O subroutines:
FOpen Open an existing file
FCreate Make a new file and open it for output
FClose Close a file opened by FOpen or FCreate
FGet1 Read one byte from a file opened by FOpen
FGet2 Read 2 bytes from a file opened by FOpen
FGet4 Read 4 bytes from a file opened by FOpen
FGet8 Read 8 bytes from a file opened by FOpen
FGet Read from a file opened by FOpen to an array
FGetSTR Read an ASCII string from a file opened by FOpen
FPut1 Write one byte to a file
FPut2 Write 2 bytes to a file
FPut4 Write 4 bytes to a file
FPut8 Write 8 bytes to a file
FPut Write data to a file directly from an array
FPutSTR Write an ASCII string to a file
FPutCRLF Write CR+LF to a file
FSeek moves the file pointer forward or backward in the file
FFlush flushes the QLIB and DOS output file buffers
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
Subroutine: DiskInfo(d$, sect%, avail%, bytes%, clust%)
Determines disk information for disk in specified drive.
D$ is the drivespec, i. e., D$ = "A:", sect% is sectors per cluster,
avail% = available clusters, bytes% = bytes per sector, and clust% =
total clusters on disk.
Example:
d$ = "a:"
CALL diskinfo(d$, a, b, c, d)
' a = sectors/cluster
' b = avail clusters
' c = bytes/sector
' d = drive clusters
PRINT a, b, c, d
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
Function: driveerror% = DiskWP (drive%)
object file: diskwp.obj
DiskWP determines if a floppy disk is ready and whether it
is write protected or not. Supports physical drives A: and B:.
driveerror% returned by DiskWP is a BIOS error code:
0 = no error
1 = invalid disk number
2 = disk not readable (not formatted, or wrong type)
3 = disk is write-protected
128 = drive not ready
Example:
REM $INCLUDE: 'qlib.bi'
drive% = 0 ' drive A:
' drive% = 1 for drive B:
driveerror% = DiskWP (drive%)
IF driveerror% THEN ... ' oops, problem
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
Subroutine: DotBAK (filename$)
object files: dotbak.obj ($asciiz.obj, strrchr.obj, strlen.obj)
DotBAK changes the name of an existing filename.ext to
filename.BAK. If filename.BAK already exists, it is deleted before
filename.ext is renamed. DotBAK updates the DOSError flag in case of
errors.
Example:
REM $INCLUDE: 'qlib.bi' ' has function declaration for DOSError
REM I want to save an old data file DATA.DAT as a backup file
REM before writing a new DATA.DAT file.
filename$ = "DATA.DAT"
CALL DotBAK (filename$) ' change existing DATA.DAT to DATA.BAK
IF DOSError THEN ... ' in case of errors
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
Subroutine: DriveSpace(drv$, total&, free&, oops%)
object file: drvspace.obj
Returns the amount of total and free space left on a given disk
drive. The drive string may be any legal disk drive, or "@" (AT sign)
for the default drive, and must be at least one character long. An
illegal drive or other error will cause oops% to be returned as -1.
Note that total& and free& are LONG integers. Works with logical
devices up to 2,147 Megabytes.
Example:
drv$="C:"
.
.
CALL DriveSpace(drv$, total&, free&, oops%)
IF oops% = -1 THEN
PRINT "Invalid drive specification"
ELSE
PRINT "Free space on drive "; drv$; " is"; free&; "bytes."
PRINT "Total space on drive "; drv$; " is"; total&; "bytes."
END IF
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
Subroutine: Exist(filename$, oops%)
object file: exist.obj ($asciiz.obj)
Tells you if a given file already exists. Returns an error code
if it doesn't, or -1 if it does. The filename must not include any
"?" or "*" wildcard characters.
Example:
filename$="QLIB.QLB"
CALL Exist(filename$, oops%)
IF oops% = -1 THEN PRINT "File already exists"
IF oops% = 0 THEN PRINT "Path exists"
' Filename$ = "d:\path"
IF oops% = 2 THEN PRINT "Path found, file not found"
IF oops% = 3 THEN PRINT "Path or file not found"
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
Subroutine: FClose(handle%)
object file: fopen.obj
Closes a file opened by FOpen or FCreate. Handle% is the file
handle returned by FOpen. FClose updates the DOSError flag.
Example:
CALL FClose(handle%)
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
Subroutine: FCopy(FromFile$, ToFile$)
object file: fcopy.obj (q$alloc.obj, q$error.obj)
Copies a file from FromFile$ to ToFile$, and updates DOSError
with an error code if something went wrong. FromFile$ and ToFile$
may not include any wildcard characters (such as * and ?). FCopy
will destroy any previously-existing file named ToFile$ before
copying the file.
Example:
REM $INCLUDE: 'qlib.bi'
FromFile$ = "b:\qlib.lib"
ToFile$ = "c:\qb4\qlib.lib"
CALL FCopy(FromFile$, ToFile$)
IF DOSError THEN ... ' check for errors
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
Function: handle% = FCreate(file$)
object file: fopen.obj ($asciiz.obj)
Creates a new file and returns a handle for subsequent writing.
If the file already exists, it will be truncated to zero bytes by
FCreate. FCreate updates DOSError.
Example:
REM $INCLUDE: 'qlib.bi'
file$ = "anyold.dat"
mode% = 1 ' access mode: write only
handle% = FOpen(file$,mode%) ' first try to open an existing file
IF DOSError = 2 THEN
handle% = FCreate(file$) ' create a new file if "anyold.dat"
' is not found
ENDIF
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
Subroutine: FFlush (handle%)
object file: fflush.obj (fseek.obj, q$error.obj)
Flushes the QLIB and DOS file output buffers associated with
handle%. The file must have been opened with QLIB's FOpen or FCreate
functions. Flushing the file buffer protects against unintended system
failures such as power outages. Any data written to the file before
calling FFlush will be safely written to the disk. FFlush also updates
QLIB's DOSError flag.
Example:
REM $INCLUDE: 'qlib.bi'
f$ = "anyold.fil"
handle% = FCreate (f$)
' program writes data to the file
.
.
.
CALL FFlush (handle%)
IF DOSError THEN ... ' check for errors
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
Subroutine: FGet(handle%, aSEG%, aPTR%, bytes%)
object file: fget.obj ($handle.obj, q$fget.obj, $fget.obj)
Reads bytes% bytes of data from a file opened by FOpen and
loads the data into an array beginning at the address pointed to
by aSEG% and aPTR%. FGet updates the DOSError flag in case of errors.
Bytes% may be as large as 32,767. If you want to read more (up to
65,535 bytes) use a LONG integer bytes& instead of bytes%.
Example:
REM $INCLUDE: 'qlib.bi'
DIM a(99)
bytes% = 200 ' 2 bytes per integer
file$ = "anyold.dat": mode% = 0 ' read-only
handle% = FOpen(file$, mode%) ' open file
aSEG% = VARSEG(a(0)) ' start at beginning
aPTR% = VARPTR(a(0))
CALL FGet(handle%, aSEG%, aPTR%, bytes%)
IF DOSError THEN ... ' check for errors
You can also declare FGet as a function to return the number of bytes
actually read from the file:
Example 2:
REM $INCLUDE: 'qlib.bi'
REM declare FGet as a function, allowing bytes to be either
REM INTEGER or LONG
DECLARE FUNCTION FGet&(h%, s%, p%, b AS ANY)
DIM a(99)
bytes% = 200 ' 2 bytes per integer
file$ = "anyold.dat": mode% = 0 ' read-only
handle% = FOpen(file$, mode%) ' open file
aSEG% = VARSEG(a(0)) ' start at beginning
aPTR% = VARPTR(a(0))
bytes& = FGet(handle%, aSEG%, aPTR%, bytes%)
IF DOSError THEN ... ' check for errors
IF bytes& <> 200 THEN ...
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
Subroutine: FGet1(handle%, n%)
object file: fget1.obj
Subroutine: FGet2(handle%, n%)
object file: fget2.obj
Subroutine: FGet4(handle%, n& [or n!])
object file: fget4.obj
Subroutine: FGet8(handle%, n#)
object file: fget8.obj
FGet[n] subroutines write a single data point to the file opened
by FOpen. FGet1 is intended for character or short integer data,
FGet2 is for INTEGER data, FGet4 is for LONG or SINGLE data and
FGet8 is for DOUBLE, CURRENCY or QLIB's COMPLEX data. Note that
SINGLE or DOUBLE data may be either IEEE format or Microsoft Binary
Format. FGet subroutines update the DOSError flag in case of errors.
Example:
REM $INCLUDE: 'qlib.bi'
handle% = FOpen(file$,0)
.
.
.
CALL FGet4(handle%, n&)
IF DOSError THEN ... ' check for errors
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
Function: s$ = FGetSTR$(handle%)
object file: fgetstr.obj ($handle.obj, $fget.obj)
FGetSTR reads an ASCII string of up to 4094 bytes from the file
associated with handle%. FGetSTR updates the DOSError flag in case
of errors.
Example:
REM $INCLUDE: 'qlib.bi'
mode% = 0 ' read only
handle% = FOpen("input.dat", mode%)
IF DOSError THEN PRINT "Error opening file":END
WHILE NOT DOSError
s$ = FGetSTR(handle)
PRINT s$
WEND
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
Function: count% = FileCount(s$, attr%)
object file: findfile.obj ($asciiz.obj)
Counts the number of files matching the filespec s$. S$ may
include the wildcard characters * and ?.
Example:
REM $INCLUDE: 'qlib.bi'
s$ ="*.*" ' count all files in the current directory
attr% = 0 ' normal files only
count% = FileCount(s$, attr%)
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
Function: fseg% = FLoad (filename$)
object files: fload.obj (q$alloc.obj, q$error.obj, $asciiz.obj)
FLoad reads a specified file into far memory, returning the segment
address of the memory block where the file is located. If an error
occurs when reading the file, FLoad returns fseg% = 0. QLIB's
DOSError flag is also updated (see DOSError in SYSTEM.DOC).
If no error occurred, DOSError returns 0; otherwise it returns an
MS-DOS error code. If fseg% = 0 and DOSError = 0 then insufficient
far memory is available. To release the memory allocated by this
function, use FreeMem(fseg%). See DATA.DOC.
Example:
REM $INCLUDE: '\qb4\qlib.bi'
filename$ = "\ramfont\italics.fnt"
iseg% = fload (filename$)
IF DOSError THEN
.
.
. ; error handling code
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
Function: handle% = FOpen(file$, mode%)
object file: fopen.obj, $handle.obj
FOpen opens an existing file for input, output or random I/O.
Access mode is 0 for read only, 1 for write only and 2 for read/write
access. File$ is any valid file name. Handle% is the file handle
returned by FOpen for use with subsequent input from or output to the
file. When a file is opened by FOpen, the MS-DOS file pointer is
positioned at the start of the file. Use FSeek to position the
pointer at the end of the file, for appending the file. FOpen
updates the DOSError flag if there was a problem.
Example:
REM $INCLUDE: 'qlib.bi'
File$ = "anyold.fil"
mode% = 0 ' read only
handle% = FOpen(file$, mode%)
IF DOSError THEN ... ' check for error
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
Subroutine: FPut(handle%, ArraySegment%, ArrayPointer%, bytes%)
object file: fput.obj ($handle.obj, q$fput.obj)
Writes data directly from an array to a file. The file must have
been opened by QLIB's FOpen in write or read/write mode, or by FCreate.
Up to 65,535 bytes may be written each time FPut is called; for more
than 32,767 bytes, use a LONG integer (bytes&) instead of bytes%.
FPut updates the DOSError flag if someting went wrong.
Example:
REM $INCLUDE: 'qlib.bi' ' FOpen and FCreate function declarations
DIM a&(599) ' 600 long integers
.
.
. ' program establishes values of the data
filename$ = "longint.dat"
CALL DotBAK(filename$) ' rename previous file to "longint.bak"
h = FCreate(filename$) ' new "longint.dat"
IF DOSError THEN PRINT "Can't open output file": GOTO FileError
s = VARSEG(a&(0)): p = VARPTR(a&(0)): n = 2400
CALL FPut(h, s, p, n)
CloseFile:
CALL FClose(h)
.
.
REM jump here if there was a problem creating the file
FileError:
.
.
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
Subroutine: FPut1(handle%, n%)
Subroutine: FPut2(handle%, n%)
Subroutine: FPut4(handle%, n& [or n!])
Subroutine: FPut8(handle%, n# [or n@])
object file: fput1.obj (q$fput.obj)
Similar to FGet[], above, but writes data to the file. The file
should have been opened with FOpen (write or read/write mode) or
by FCreate. FPut[] subroutines leave an error code in the DOSError
flag if something went wrong.
FPut1 writes a single byte or character
FPut2 writes a 2-byte INTEGER
FPut4 writes 4 bytes of data, such as a LONG or SINGLE value
FPut8 writes 8 bytes of data, such as DOUBLE or CURRENCY values
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
Subroutine: FPutCRLF(handle%)
object file: fputcrlf.obj ($handle.obj, q$fput.obj)
Subroutine: FPutSTR(handle%, s$)
object file: fputstr.obj ($handle.obj, q$fput.obj)
FPutSTR writes a string to an output file, updating the DOSError
flag if something went wrong. FPutSTR does not write CR+LF at the
end of the string; use FPutCRLF to write to the next line in the file.
Example:
REM $INCLUDE: 'qlib.bi'
REM I want to copy "input.dat" to "output.dat"
REM while filtering out references to "stupid boss"
stupid$ = "stupid boss"
inhandle = FOpen("input.dat", 0) ' read only
IF DOSError THEN PRINT "Error opening input file":END
outhandle = FOpen("output.dat", 1) ' write only
IF DOSError THEN PRINT "Error opening output file":END
WHILE NOT DOSError
s$ = FGetSTR(inhandle)
IF DOSError GOTO EndOfFile
IF INSTR(s$, stupid$) = 0 THEN
CALL FPutSTR(outhandle, s$)
CALL FPutCRLF(outhandle)
ENDIF
WEND
EndOfFile:
CALL FClose(inhandle)
CALL FCLose(outhandle)
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
Subroutine: FSeek(handle%, bytes&, seekmode%)
object file: fseek.obj ($handle.obj)
Moves the file pointer from its present position forward or
backward in the file. The file must have been opened by FOpen
or FCreate. Bytes& is the number of bytes to move the pointer.
Seekmode% = 0 if bytes& is absoute offset from start of file
= 1 if bytes& is signed offset from current file pointer
= 2 if bytes& is signed offset from end of file
Example:
CALL FSeek(handle%, bytes&, seekmode%)
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
Function: s& = FSize (handle%)
object file: fsize.obj (d$error.obj)
Given a valid file handle returned by a QLIB FOpen
subroutine, FSize returns the size of the file. Any DOS errors
are flagged by DOSError (see DOSError in SYSTEM.DOC).
Example:
REM $INCLUDE: 'qlib.bi'
handle% = FOpen(file$, mode%)
IF DOSError THEN . . . ' error control stuff
s& = FSize(handle%)
IF DOSError THEN . . . ' error control stuff
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
Function: d$ = GetDRIVE
object file: getdrive.obj
Returns the default drive.
Example:
REM $INCLUDE: 'qlib.bi'
.
.
.
drive$ = GetDRIVE
PRINT "The default drive is "; drive$
REM drive$ includes the trailing colon, i.e., drive$ = "C:"
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
Function: sub$ = GetSUB(d$)
object file: getsub.obj ($asciiz.obj, strncpy.obj)
Gets the current directory on disk d$. To get the current
directory on the default drive, set d$ = "@". If d$ specifies an
invalid drive, sub$ will be a nul string. NOTE: d$ must be at least
one character long.
Example:
REM $INCLUDE: 'qlib.bi'
d$ = "C:"
sub$ = GetSUB(d$)
IF sub$ = "" THEN PRINT d$ + " is not a valid drive"
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
Subroutine: FindFirstMatch(file$, fAttr%, oops%)
Subroutine: FindNextMatch(oops%)
Subroutine: FindFileName(filename$, flen%)
Subroutine: FindFileAttr(fAttr%)
Subroutine: FindFileDate(month%, day%, year%)
Subroutine: FindFileTime(hour%, min%, sec%)
Subroutine: FindFileSize(lowword%, highword%)
object file: findfile.obj ($asciiz.obj)
This group of subroutines may be used to search for files which match
a specified file name. The specified file name may include drive and
path, and may also include the * and ? wildcards. These subroutines may
be used to duplicate the DOS DIR command.
A search attribute (fAttr%) may also be specified. File attributes are
listed on the first page of this file.
fAttr% may include more than one type of file. For example, if
fAttr% = 2 + 8, FindFirst/NextMatch will search for hidden and system
files as well as normal files (normal files will always be found).
The actual file attribute of the matched file will be returned by
FindFileAttr. Files returned may have a combination of attributes; for
example, if a file attribute returned by FindFileAttr is 18 ( = 2 + 16),
this file is a hidden directory.
The file size returned by FindFileSize is in two parts. Use the following
code to determine the file size:
CALL FindFileSize(lowword%, highword%) ' assumes file matched with
' FindFirst/NextMatch, oops% <> 0
size& = CLNG(lowword%)
IF lowword% < 0 THEN size& = size& + 65536&
size& = size& + highword% * 65536&
see examples on the next page
Example 1:
filename$ = SPACE$(12) ' filename$ must be initialized
' as a 12-byte (or longer) string
' or the namelen% will be returned
' as -1
FileSpec$ = "\qb4\*.bas"
fAttr% = 0 ' search only for normal files
CALL FindFirstMatch(FileSpec$, fAttr%, oops%)
IF oops% = -1 THEN PRINT "FileSpec$ is a nul string"
IF oops% THEN PRINT "No matching files"
WHILE oops% = 0
CALL FindFileName(filename$, namelen%)
IF namelen% = -1 THEN PRINT "filename$ shorter than 12 bytes"
PRINT LEFT$(filename$, namelen%)
CALL FindNextMatch(oops%)
WEND
REM FindFileName, FindFileAttr, FindFileDate, FindFileTime and
REM FindFileSize will return usable results only after a successful
REM (oops% = 0) call to FindFirstMatch or FindNextMatch.
Example 2:
REM In this example, we will print all subdirectories one
REM level down from the root directory
filename$ = SPACE$(12) ' filename$ must be initialized
' as a 12-byte (or longer) string
fAttr% = 16
FileSpec$ = "\*.*"
CALL FindFirstMatch(FileSpec$, fAttr%, oops%)
IF oops% THEN PRINT "No files or subdirectories"
WHILE oops% = 0
CALL FindFileAttr(fAttr%)
IF fAttr% AND 16 THEN
CALL FindFileName(filename$, namelen%)
PRINT LEFT$(filename$, namelen%)
END IF
CALL FindNextMatch(oops%)
WEND
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
Subroutine: GetFileAttr(file$, attr%, oops%)
object file: fileattr.obj ($asciiz.obj)
Returns the attribute of file$. File$ must not include
any * or ? wildcards. File attributes are listed on the first page
of this file. Oops% is an MS-DOS error code if something went wrong,
or oops% = -1 if no problems were encountered.
Example:
file$ = "c:\qb4\qlib.lib"
CALL GetFileAttr(file$, attr%, oops%)
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
Function: ok% = GoodDrive(d$)
object file: goodrive.obj
GoodDrive determines if a logical drive is valid. D$ is the drive
name, i. e., d$ = "A:", "B:", etc. Ok% = 0 if the drive is not a valid
drive, or ok% = -1 if the drive is a logical device in the system.
Example:
REM $INCLUDE: 'qlib.bi'
REM determine names of logical devices
FOR i = 0 to 25
d$ = CHR$(65 + i)
IF GoodDrive(d$) THEN PRINT d$
NEXT
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
Subroutine: KillFile(file$, oops%)
object file: killfile.obj ($asciiz.obj)
KillFile deletes file$ from a disk with error trapping, avoiding
BASIC's ON ERROR. Oops% = 0 if no error; MS-DOS error codes apply if
oops% <> 0.
Example:
file$ = "oldfile.dat"
CALL KillFile(file$, oops%)
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
Subroutine: KillSUB(sub$, oops%)
object file: killfile.obj ($asciiz.obj)
KillSUB deletes subdirectory sub$ from a disk with error trapping,
avoiding BASIC's ON ERROR. The subdirectory must be empty before it is
deleted. Oops% = 0 if no error; MS-DOS error codes apply if oops% <> 0.
Example:
sub$ = "C:\123"
CALL KillSUB(sub$, oops%)
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
Subroutine: MakeSUB(sub$, oops)
object file: killfile.obj ($asciiz.obj)
Creates a new subdirectory. Oops% is an MS-DOS error code returned
by MakeSUB. If oops% = 0 then no error was detected.
Example:
sub$ = "\qb4\qlib" ' make a new subdirectory for QLIB
CALL MakeSUB(sub$, oops%)
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
Subroutine: Rename(old$, new$, oops)
object file: rename.obj ($asciiz.obj)
Changes filename old$ to new$, returning an MS-DOS error code.
Similar to BASIC's NAME function, but does not require ON ERROR
to trap errors. You may use Rename to move a file from one directory
to another on the same disk.
Example:
old$ = "demo.bas"
new$ = "demo.bak"
CALL Rename(old$, new$, oops)
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
Subroutine: SetDRIVE(d$)
object file: setdrive.obj
Sets d$ as the default drive. D$ may be any valid disk drive or
other logical device (such as a RAMdisk). SetDRIVE also updates the
DOSError flag if an invalid drive is specified.
Example:
d$ = "a:" ' the drive specifier d$ may be upper or lower
' case and need not include the colon.
CALL SetDRIVE(d$) ' drive A: is now the default drive
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
Subroutine: SetFileAttr(file$, attr%, oops%)
object file: fileattr.obj ($asciiz.obj)
Changes the file attribute of file$. File attributes are
described on the first page of this file. Oops% returned by this
subroutine is an MS-DOS error code (see first page of this file).
If all O.K. then oops% = -1.
Example: I want to make my QLIB.LIB file read-only
REM I start by getting the present attribute
file$ = "QLIB.LIB"
CALL GetFileAttr(file$, attr%, oops%)
IF oops% <> -1 THEN
REM Uh oh, something went wrong
.
.
.
END IF
REM now I'll add the Read-only bit to the attribute
attr% = attr% OR 1
CALL SetFileAttr(file$, attr%, oops%)
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
Subroutine: SetFileDate(file$, month%, day%, year%, hour%, min%, sec%)
object file: setfdate.obj ($asciiz.obj)
Sets file time/date stamp. The year may be either a four digit
or two digit number (e.g., either 1986 or just 86). DOS will round
the seconds value off to the next lower even number. If there is a
problem with the filename, or if the file is read-only, the month will
be returned as -1. Note that midnight is 24:00. If hour%, minute% and
second% are all 0, then the file's time will not be displayed in a
directory list.
Example:
file$ = "anyfile.dat"
CALL SetFileDate(file$, month%, day%, year%, hour%, min%, sec%)
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
Subroutine: SetSUB(sub$, oops%)
object file: killfile.obj ($asciiz.obj)
Changes the default subdirectory to sub$. Oops% is an error
code returned to BASIC.
SetSUB's error codes:
oops% = 0 no error
1 subdirectory name is a nul string
3 path not found
Example:
directory$ = "\qb4\lib"
CALL SetSUB(directory$, oops%)