What is the fastest way of cheking if a file exists?

Just starting out? Need help? Post your questions and find answers here.
RichardL
Enthusiast
Enthusiast
Posts: 532
Joined: Sat Sep 11, 2004 11:54 am
Location: UK

Post 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