FileExist

Tests for the existence of files.

Syntax:

FileExist (filename)

Parameters:

(s) filename either a fully qualified filename with drive and path, or just a filename and extension.

Returns:

(i) @TRUE (1) if the file exists; @FALSE (0) if it doesn't exist or if the pathname is invalid.; (2) if the specified file exists but is currently open by another application in read deny mode.

 

This function is used to test whether or not a specific file exists.

If a fully-qualified file name is used, only the specified drive and directory will be checked for the desired file. If only the root and extension are specified, then first the current directory is checked for the file, and then, if the file is not found in the current directory, all directories in the DOS path are searched.

FileExist returns "2" if the specified file exists but is currently open by another application in read deny mode. If you try to access this file using (most of) the other "File..." functions, it will cause a sharing violation.

FileExist does not support wild-carded file names. Here is a workaround.

If FileItemize("c:\somedir\*.*")==""
   Message("","No files were found")
Else
   Message("","Files were found")
EndIf

This function supports extended-length path names.

Examples:
; check for file in current directory
fex = FileExist(StrCat(DirGet( ), "myfile.txt"))
If fex
   Message("MyFile.Txt"," Is in the current directory")
Else
   Message("MyFile.Txt","Is NOT in the current directory")
endif 
See Also:

DirExist, FileLocate