home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Frostbyte's 1980s DOS Shareware Collection
/
floppyshareware.zip
/
floppyshareware
/
GLEN
/
QLIB43.ZIP
/
DISK.DOC
< prev
next >
Wrap
Text File
|
1990-03-16
|
18KB
|
508 lines
DISK / FILE routines look for specified files on your disk, or report
disk status. Several QLIB disk/file subroutines return the following
MS-DOS error codes:
oops% = 2 file not found
oops% = 3 path not found
oops% = 4 too many open files
oops% = 5 access denied (file may be read-only
or a subdirectory)
BIOS error codes, returned by DriveReady, are:
oops% = 2 disk not readable (not formatted, or wrong type)
oops% = 128 drive not ready
File attributes may be combined. Each bit of the 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 17 is a hidden subdirectory (16 + 1)
Subroutine: CopyFile(FromFile$, ToFile$, oops%)
Copies a file from FromFile$ to ToFile$, and returns an error
code if something went wrong. FromFile$ and ToFile$ may not include
any wildcard characters (such as * and ?). CopyFile will destroy any
previously-existing file named ToFile$ before copying the file.
Oops% = -1 if an error in the "To" file was encountered; other error
codes apply to the "From" file.
Example:
FromFile$ = "b:\qlib.lib"
ToFile$ = "c:\qb4\qlib.lib"
CALL CopyFile(FromFile$, ToFile$, oops%)
Subroutine: DriveReady(drv$, oops%)
DriveReady is used to determine if a floppy disk drive has a usable
disk and is ready for use. DriveReady returns BIOS error codes, or
oops% = 0 if the drive is ready. Oops% = -1 if drv$ is an invalid
drive specification.
Example:
drv$ = "a:"
CALL DriveReady(drv$, oops)
IF oops% <> 0 THEN PRINT "Drive " + drv$ + "not ready or bad disk"
Subroutine: DriveSpace(drv$, total&, free&, oops%)
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. See "QLIB and QB3" in
APPENDIX.DOC to use this subroutine. 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%)
Tells you if a given file already exists. Returns an error code
if it doesn't, or -1 if it does. Requires an ASCIIZ filename without
wildcards.
Example:
filename$="TEST.TXT" + CHR$(0)
CALL Exist(filename$, oops%)
IF oops% = -1 THEN PRINT "File already exists"
IF oops% = 0 THEN PRINT "Path exists"
' Filename$ = "d:\path" + CHR$(0)
IF oops% = 2 THEN PRINT "Path found, file not found"
IF oops% = 3 THEN PRINT "Path or file not found"
QLIB's file Input/Output subroutines provide fast, flexible file handling,
replacing QB's clumsy functions. Below is a summary of QLIB's file I/O
subroutines:
FileOpen Open a file for input, output or random access
FileCreate Make a new file and open it for I/O
FileClose Close a file opened by FileOpen
FileRead Read from a file opened by FileOpen directly
to an array
FileWrite Write data to a file directly from an array
FileBegin Reset the MS-DOS file pointer to the beginning of
the file
FileEnd Sets the MS-DOS file pointer to end of the file,
to append data to the file
FileSetPTR sets the file pointer for an open file to a specified
byte position in the file
FileMovPTR moves the file pointer forward or backward in the file
QLIB's file I/O subroutines return an error code (oops%) which is zero if
no error occurred, or returns an MS-DOS error code if something went wrong.
Subroutine: FileBegin(handle%, oops%)
Sets the MS-DOS file pointer to the beginning of a file opened by
FileOpen. Handle% is the file handle returned by FileOpen.
Example:
CALL FileBegin(handle%, oops%)
Subroutine: FileClose(handle%, oops%)
Closes a file opened by FileOpen. Handle% is the file handle returned
by FileOpen. Returns an MS-DOS error code.
Example:
CALL FileClose(handle%, oops%)
Subroutine: FileCreate(file$, handle%, oops%)
Creates a new file and returns a handle for subsequent writing.
If the file already exists, it will be truncated to zero bytes by
FileCreate.
Example:
file$ = "anyold.dat" +CHR$(0)
CALL FileOpen(file$, handle%, oops%)
' first try to open an existing file
IF oops% = 2 THEN
CALL FileCreate(file$, handle%, oops%)
' create a new file if "anyold.dat"
' is not found
Subroutine: FileEnd(handle%, oops%)
Sets the MS-DOS file pointer at the end of the file. Subsequent
FileWrite calls will add new data to the end of the file.
Example:
file$ = "anyfile.dat" + CHR$(0)
acode = 1 ' I want to add new data to this file
CALL FileOpen(a$, acode%, handle%, oops%)
CALL FileEnd(handle%, oops%)
Subroutine: FileMovPTR(handle%, bytes0&, bytes1&, oops) (QB4+)
Moves the file pointer from its present position forward or
backward in the file. The file must have been opened by FileOpen
or FileCreate. Bytes0& is the number of bytes to move the pointer,
and bytes1& is the resulting pointer location in the file. Note that
bytes0& and bytes1& are LONG integers.
Example:
CALL FileMovPTR(handle%, bytes0&, bytes1&, oops%)
Subroutine: FileOpen(file$, acode%, handle%, oops%)
FileOpen opens an existing file for input, output or random I/O.
If acode% = 0, access is input, if acode% = 1, access is output, and if
acode% = 2 then access may be either input or output. File$ is an
ASCIIZ (zero-terminated) file name. Handle% is the file handle returned
by FileOpen for use with subsequent input to or output from the file.
When a file is opened by FileOpen, the MS-DOS file pointer is positioned
at the start of the file. Use FileEnd to position the pointer at the
end of the file, for appending the file.
Example:
File$ = "anyold.fil" + CHR$(0)
acode% = 2 ' I want to both read from the file
' and write new data to the file
' without closing and re-opening it
CALL FileOpen(file$, acode%, handle%, oops%)
Subroutine: FileRead(handle%, aSEG%, aPTR%, bytes0%, bytes1%, oops%)
Reads bytes0% bytes of data from a file opened by FileOpen and
loads the data into an array beginning at the address pointed to
by aSEG% and aPTR%. bytes1% is the number of bytes actually read
into the array. Unless FileRead encounters the end of the file,
bytes1% should be the same as bytes0%.
Example:
DIM a(99) ' an integer array of 100 elements
bytes0% = 200 ' each integer is 2 bytes
file$ = "anyold.dat" + CHR$(0)
CALL FileOpen(file$, handle%, oops%)
aSEG% = VARSEG(a(0)) ' start at beginning of file
aPTR% = VARPTR(a(0))
CALL FileRead(handle%, aSEG%, aPTR%, bytes0%, bytes1%, oops%)
Subroutine: FileSetPTR(handle%, bytes0&, bytes1&, oops%)
Sets the current location of the file pointer for a file opened
by FileOpen or FileCreate. Bytes0& is the desired position and bytes1&
is returned by FileSetPTR. Note that bytes0& and bytes1& and LONG
integers.
Example:
CALL FileSetPTR(handle%, bytes0&, bytes1&, oops%)
Subroutine: FileWrite(handle%, aSEG%, aPTR%, bytes0%, bytes1%, oops%)
Similar to FileRead, above, but writes to the file from the array.
Subroutine: GetDRIVE(drv%)
Returns the ASCII character code of the default drive.
Example:
CALL GetDRIVE(drv%)
drive$ = CHR$(drv%)+":"
PRINT "The default drive is "; drive$
Subroutine: GetSUB(d$, sub$, sublen%)
Gets the current directory on disk d$. The subdirectory string must
be 64 characters long. Note that the returned string will NOT be started
by a backslash "\" character - you should add one if appropriate. To get
the current directory on the default drive, set d$ = "@". If d$ specifies
an invalid drive, sublen% will be returned -1. NOTE: d$ must be at least
one character long.
Example:
sub$ = SPACE$(64)
d$ = "C"
CALL GetSUB(d$, sub$, sublen%)
IF sublen% = -1 THEN
PRINT d$ + " is not a valid drive"
ELSE
sub$ = "\" + LEFT$(sub$, sublen%)
END IF
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%)
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
(QB4+)
size& = CLNG(lowword%)
IF lowword% < 0 THEN size& = size& + 65536&
size& = size& + highword% * 65536&
(QB2, QB3)
size# = CDBL(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"+CHR$(0) ' FileSpec$ must end in CHR$(0)
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
fAttr% = 16
FileSpec$ = "\*.*"+CHR$(0)
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$ + CHR$(0), attr%, oops%)
Returns the attribute of file$. File$ must be an ASCIIZ
(zero-terminated) string without the * 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" + CHR$(0)
CALL GetFileAttr(file$, attr%, oops%)
Subroutine: KillFile(file$ + CHR$(0), oops%)
KillFile deletes file$ from a disk with error trapping, avoiding
QB's ON ERROR. Note that the file name string passed to the subroutine
is an ASCIIZ (zero-terminated) string.
Oops% codes are:
0 = no error
1 = file name is a nul string
2 = file not found
3 = path not found
5 = file is read-only
19 = disk is write-protected
Example:
file$ = "oldfile.dat" + CHR$(0)
CALL KillFile(file$, oops%)
Subroutine: KillSUB(sub$ + CHR$(0), oops%)
KillSUB deletes subdirectory sub$ from a disk with error trapping,
avoiding QB's ON ERROR. Note that the directory name string passed to
the subroutine is an ASCIIZ (zero-terminated) string. The subdirectory
must be empty before it is deleted.
Oops% codes are:
0 = no error
1 = subdirectory name is a nul string
3 = path not found
5 = usually means files are still in the directory, or it may
mean the subdirectory is read-only
19 = disk is write-protected
Example:
sub$ = "C:\123" + CHR$(0)
CALL KillSUB(sub$, oops%)
Subroutine: MakeSUB(sub$ + CHR$(0), oops)
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$ + CHR$(0), oops%)
Subroutine: Rename(old$, new$, oops)
Changes filename old$ to new$, returning an MS-DOS error code.
Similar to QuickBASIC's NAME function, but does not require ON ERROR
to trap errors. Note that both old$ and new$ must be zero-terminated
ASCIIZ strings. You may use Rename to move a file from one directory
to another on the same disk.
Example:
old$ = "demo.bas" + CHR$(0)
new$ = "demo.bak" + CHR$(0)
CALL Rename(old$, new$, oops)
Subroutine: SetDRIVE(d$)
Sets d$ as the default drive. D$ may be any valid disk drive or
other logical device (such as a RAMdisk).
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$ + CHR$(0), attr%, oops%)
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" + CHR$(0)
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%)
Sets file time/date stamp. The filename must be an ASCIIZ (zero-
terminated) string. 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" + CHR$(0)
CALL SetFileDate(file$, month%, day%, year%, hour%, min%, sec%)
Subroutine: SetSUB(sub$ + CHR$(0), oops%)
Changes the default subdirectory to sub$. Oops% is an error
code returned to QuickBASIC.
SetSUB's error codes:
oops% = 0 no error
1 subdirectory name is a nul string
3 path not found
Note that sub$ is an ASCIIZ (zero-terminated) string.
Example:
directory$ = "\qb4\library" + CHR$(0)
CALL SetSUB(directory$, oops%)