DISK I/O
Test if a file exists
Try the following function:
LOCAL FN FileCheckExist(FileName$,VolRefNum%)
DIM ParamBlock.ioHFQElSiz
ParamBlkPtr&=VARPTR(ParamBlock)
DEF BLOCKFILL (ParamBlkPtr&,128,0)
DoesExist%=_False
ParamBlock.ioVRefNum = VolRefNum%
ParamBlock.ioNamePtr& = @FileName$
osErr%=FN HGETFILEINFO(ParamBlkPtr&)
LONG IF osErr%=_noErr
ParamBlock.iocompletion% = _noErr
DoesExist%=_True
XELSE
DoesExist%=_False
END IF
END FN = DoesExist%
Call it using the following:
FileName$= "ThisIsMyFile"
VolRefNum%=prefsVol%
DoesExist%=FN FileCheckExist(FileName$,VolRefNum%)
LONG IF DoesExist%=_True
PRINT "Yes, it exists"
XELSE
PRINT "No, it does not exist"
END IF
|