Page 1 of 1

Posted: Thu Sep 11, 2008 4:51 pm
by RichardL
I wrote and have used this for many years and it has never thrown a wobbly... Windoze only.

Code: Select all

Procedure.l Exist(File$)                               ;- Check a drive + file exists, without system requesters etc.
  ; Check if a drive or drive+file exists
  ; Return -1 if exists, else 0
  ; *** Never *** displays a system error even if device is missing
  ; such as a multi card interface with no cards plugged in.
  
  Protected EFlag.l, OldErrorMode.l, Junk.l
  
  OldErrorMode = SetErrorMode_(1)   ; Turn off screen error messages
  If GetFileAttributes_(@File$)=-1  ; Get file butes. -1 = fail
    Junk.l=GetLastError_()          ; Get last error, to flush system
    SetLastError_(0)                ; Set error to zero
    EFlag.l = 0                     ; Return value to flag FAIL
  Else
    EFlag.l = -1                    ; Return value to flag a PASS
  EndIf
  SetErrorMode_(OldErrorMode)       ; Reset the error flags
  ProcedureReturn EFlag
EndProcedure