Function FExists() Foundation

Determines whether the specified file exists.

FExists( <cFileName>, [<cFileAttribute>] ) --> lExists
<cFilename> is a character string specifying a file. It can be a full qualified file name using drive-letter or UNC notation and may include a file mask containing wildcards (? and *) to identify groups of files.
The argument <cFileAttribute> is a string which can be used to specify a search condition based on file attributes. The string may include one or more of the following characters: "D","H","S","A","R". The meaning of these characters is the same as for FAttr() . <cFileAttribute> defaults to "RA" (Read-only and Archive attribute).
The search rule for file attributes can be modified with an additional character listed below:
Attribute modifiers
Modifier Description
+ Check files having this attribute set (prefix notation)
- Ignore files having this attribute set (prefix notation)
= Ignore default settings and force exact match. The equal sign must be the first character, if used.
* Match the defined attributes regardless of whether or not other attributes are set. The asterisk must be the last character, if used.

The functions returns .T. (true) if the file exists, otherwise .F. (false).


The FExists() function is a low level file function which determines if a file with a given name and the optional attribute limitation exists. In contrast to File() , the directories specified with SET DEFAULT or SET PATH are not included in the search. FExists() searches files only in the directory specified with<cFileName>, or in the current directory when the parameter contains no directory information. If <cFileName> includes a relative path, the search begins in the current directory of the current drive.

Since FExists() searches files independently of the SET PATH/SET DEFAULT settings, it is the recommended function to check for the existence of files.

// The example demonstrates the difference between the 
// FExists() and File() functions and shows a recommended 
// scenario for file creation. 

#include "" 

   LOCAL nHandle 

   ? CurDirectory()                // Result: C:\users\james\documents\Xbase++ 

   ? File( "Customer.dbf" )        // Result: .F. 
   ? FExists( "Customer.dbf" )     // Result: .F. 

   SET DEFAULT TO "source\samples\data\misc" 

   ? File( "Customer.dbf" )        // Result: .T. 
   ? FExists( "Customer.dbf" )     // Result: .F. 

   // Low level file creation 
   IF .NOT. FExists( "\ALASKA\SYSDATA.LOG", "=H*" ) 
      nHandle := FCreate( "\ALASKA\SYSDATA.LOG" ) 
      FAttr( "\ALASKA\SYSDATA.LOG", "H" ) 
      nHandle := FOpen( "\ALASKA\SYSDATA.LOG", FO_READWRITE ) 

   FWrite( nHandle, DtoS( Date() ) + Time(), 16 ) 
   FClose( nHandle ) 



If you see anything in the documentation that is not correct, does not match your experience with the particular feature or requires further clarification, please use this form to report a documentation issue.