This little function (below) calls upon a little known DOS call (&H60).
When passed a filespec, it expands the spec to a complete drive - path
- filename. If the spec has any illegal characters in it, DOS sends
back an error code of 2 (normally this means "file not found"). That
could be useful.
However, if the spec names a non-existant file or path, this function
won't flag it. If the spec uses a reserved DOS name, it sometimes
confuses this function, also. That's not so useful. Play with it. If
you can think of a good use for it, use it.
-----------------------------------------------------------------
$LIB ALL OFF
DECLARE FUNCTION ValidSpec% (InSpec$, ErrCode%)
DO
LINE INPUT "Enter a file spec: " ; Spec$
IF LEN(Spec$) = 0 THEN EXIT LOOP
Valid% = ValidSpec%(Spec$, ErrCode%)
PRINT "Spec$ after call to DOS: "; Spec$
PRINT
IF ErrCode% THEN PRINT "Error reported: "; ErrCode%
IF Valid% THEN
PRINT "Valid spec!"
ELSE
PRINT "NOT valid spec..."
END IF
PRINT
LOOP
END
'=============================================
FUNCTION ValidSpec% (Spec$, ErrCode%) PUBLIC
'=============================================
' When passed a file spec, this function determines if it contains
' all valid characters. If valid, it returns -1 and an errcode of zero.
' If invalid it returns a zero and the error code returned by DOS.
' This function expands specs that contain wildcard characters (?*),
' and filespecs that begin with a ".\" or "..\".
DIM ErrorCode AS LOCAL INTEGER
DIM Success AS LOCAL INTEGER
ErrorCode = 0 'assume success
Success = -1
DIM InStringSeg AS LOCAL WORD
DIM InStringOff AS LOCAL WORD
DIM OutStringSeg AS LOCAL WORD
DIM OutStringOff AS LOCAL WORD
DIM OutString AS LOCAL STRING * 70
IF LEN(Spec$) THEN
InSpec$ = Spec$ + CHR$(0) ' make an ASCIIZ from input spec
InStringSeg = STRSEG(InSpec$)
InStringOff = STRPTR(InSpec$)
OutStringSeg = VARSEG(OutString)
OutStringOff = VARPTR(OutString)
ASM Push DS
ASM Push SI
ASM Push DI
ASM Mov AX, &H6000
ASM Mov ES, OutStringSeg
ASM Mov DI, OutStringOff
ASM Mov SI, InStringOff
ASM Mov DS, InStringSeg
ASM Int &H21
ASM Jc WasError
ASM Xor AX, AX
WasError:
ASM Mov ErrorCode, AX
ASM Pop DI
ASM Pop SI
ASM Pop DS
IF ErrorCode THEN
Success = 0 ' error code = invalid file name(?)
ELSE ' retrieve expanded file spec into OutSpec$
Spec$ = MID$(OutString, 1, INSTR(OutString, CHR$(0)) - 1)
END IF
ELSE
ErrorCode = 2 ' treat null spec as "file not found
Success = 0 ' not a valid spec
END IF
ErrCode% = ErrorCode
ValidSpec% = Success
END FUNCTION
* SLMR 2.1a * MAXLIB For PB v1.1 - Access arrays and files in EMS/XMS!
--- WILDMAIL!/WC v4.12
---------------
* Origin: Com-Dat BBS - Hillsboro, OR. HST DS (1:105/314.0)
|