Function File() Foundation

Determines whether the specified file exists.

Syntax
File( <cFilename>, [<cAttribute>] ) --> lExist
File( @<cFilename>, [<cAttribute>] ) --> lExist
Parameters
<cFilename>
<cFilename> is a character string specifying a file. It can include the drive and path as well as a file mask containing wildcards (? and *) to identify groups of files.
@ <cFilename>
If the parameter <cFilename> is passed by reference and <cFilename> contains a file without path or drive or a relative path, the full qualified file name is assigned to the parameter <cFilename>.
<cAttribute>
For <cAttribute> one of the three characters "D","H","S" may be used. The meaning is as follows:
File attributes for File()
Attribute Meaning
D Directory - File is a directory
H Hidden - Hidden file
S System - System file
Return

The return value of File() is .T. (true) when a file was found corresponding to the specification in <cFilename>. When no file was found, File() returns the value .F. (false).

Description

The environment function File() tests whether one or more files exist matching the specification <cFilename>. When the path is not specified in <cFilename>, File() uses the settings returned by SET DEFAULT and SET PATH and aborts the search with the first match. The system path defined at the operating system level with SET PATH is not searched.

to have the function recognize directories, hidden or system files the appropriate character must be specified as the second argument.

Examples
Check if a file exists
// The example shows the dependence between File() and the 
// settings with SET PATH and SET DEFAULT 

PROCEDURE Main 

   ? File("address.dbf")                 // result: .F. 
   ? File("\xpp\samples\data\misc\address.dbf")       // result: .T. 

   SET PATH TO \xpp\samples\data\misc 

   ? File("address.dbf")                 // result: .T. 

   SET PATH TO 
   SET DEFAULT TO \xpp\samples\data\misc 

   ? File("address.dbf")                 // result: .T. 
   ? File("*.DBF")                       // result: .T. 

   SET DEFAULT TO 
   ? File( "\xpp\samples\data\misc", "D" ) // result: .T. 
RETURN 
Feedback

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.