Links are not active on this page.
 FILE( ) Function

Locates the specified file.

FILE(cFileName [, nFlags])

Parameters

cFileName

Specifies the name of the file to locate. cFileName must include the file extension. You can include a path with the file name to search for a file in a directory or on a drive other than the current directory or drive.

If you do not include a path with the file name, Visual FoxPro searches in the default directory for the file. If it cannot find the file in the default directory, Visual FoxPro searches along the Visual FoxPro path, which is established with SET PATH.

NoteTip

Files included in an APP or EXE FoxPro application have precedence over the files on a disk. The path is irrelevant for such files. Use ADIR( ) function to locate specified file on a disk only.

nFlags

Specifies the kind of value FILE( ) returns when the file exists but might be marked with the Hidden or System attribute. The following table lists the values for nFlags.

nFlags Description

0

FILE( ) returns False (.F.) if the file exists but is marked with a Hidden or System attribute. (Default)

1

FILE( ) returns True (.T.) if the file exists, regardless of its file attributes. Setting nFlags to 1 allows you to check for hidden or system files.

Expand imageReturn Value

Logical data type. FILE( ) returns True (.T.) if the specified file is included in an application or found on a disk; otherwise, it returns False (.F.).

Expand imageRemarks

You can use the ADIR( ) function to retrieve specific attributes for the file.

You can use the CD and CHDIR commands to switch to hidden files and directories.

Expand imageExample

The following example displays a message indicating if the Visual FoxPro resource file exists in the Visual FoxPro startup directory.

 CopyCode imageCopy Code
SET PATH TO HOME( )
CLEAR
IF FILE('foxuser.dbf')
   WAIT WINDOW 'Visual FoxPro resource file present'
ELSE
   WAIT WINDOW 'Visual FoxPro resource file not present'
ENDIF

Expand imageSee Also