LOCFILE( ) Function

See Also

Locates a file on disk and returns the file name with its path.

Syntax

LOCFILE(cFileName [, cFileExtensions] [, cFileNameCaption])

Returns

Character

Arguments

cFileName

Specifies the name of the file to locate. If cFileName includes only a file name, LOCFILE( ) searches the Visual FoxPro default directory or folder first. If the file isn't found in the default directory or folder, the Microsoft Visual FoxPro path is then searched. Use SET PATH to specify the Visual FoxPro path.

If cFileName includes a path and a file name, the specified location is searched. If the file can't be found in the specified location, LOCFILE( ) searches the Visual FoxPro default directory or folder and then the Visual FoxPro path.

If the file is located, LOCFILE( ) returns the file name and path.

cFileExtensions

Specifies file extensions for the file to locate. If the file name you specify with cFileName doesn't include an extension, Visual FoxPro applies the file extensions listed in cFileExtensions to the file name and searches for the file again.

cFileExtensions also specifies the file name extensions of the files displayed in the Open dialog box when the file you specified can't be located.

cFileExtensions can take a variety of forms:

cFileNameCaption

Specifies the text you want to use to prompt the user. The text appears to the left of the textbox in which you enter the file name. If omitted, "File name:" is displayed.

For a list of Visual FoxPro file extensions and corresponding creator types, see the File Extensions and File Types online topic.

Remarks

The Open dialog box is displayed if the file can't be located in the default directory or folder, the Visual FoxPro path, or a specified location. The Open dialog box can be used to locate the file. When a file is chosen from the Open dialog box, the file name is returned with the file's path.

If you exit the Open dialog box by choosing Cancel, pressing ESC, or choosing Close from the Control menu, Visual FoxPro generates an error message and LOCFILE( ) doesn't return a value.