File(), Directory()
These two handy functions check whether a file or directory exists. If there's any doubt in your mind before trying to open a file, or if you want to make sure there isn't an output file by that name and offer the user the option of supplying a new name or overwriting, these are the functions for you. Usage | lFileExists = FILE( cFilePath ) lDirExists = DIRECTORY( cDirectory ) |
If no directory is specified, in addition to the current directory, FoxPro also searches the FoxPro PATH (not the DOS path) set with the SET PATH statement, and returns .T. if the file is found anywhere along that path. It can be argued that "It's a feature, not a bug," as we might in the section by that name, but this one trips us up often. To specify that FILE()searches only the current directory, you must explicitly specify at least the directory path name, starting at the root of the drive. So you'll probably want to type this command as |
Example | lOutFileHere = FILE("OutPut.PRN") lDirExists = DIRECTORY("C:\Temp") |
See Also | ADir(), CurDir(), Set Path |
View Updates
Copyright © 2002 by Tamar E. Granor, Ted Roche, Doug Hennig, and Della Martin. All Rights Reserved.