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.
lFileExists = FILE( cFilePath )
lDirExists = DIRECTORY( cDirectory )
FILE()
returns a logical value if the specified file name exists in the specified directory. So far, so good.
Note that when you use FILE(cPath + cFilename) within an EXE, it returns .T. if the file exists in the EXE, even when the file doesn't exist in the specified directory. You have to use ADIR()
to see if the file exists in the directory.
DIRECTORY()
tells us whether a directory exists. The parameter can be a relative path ("..\MyDir") or explicit from the root of the drive (" C:\MyDir\MySubDir") and isn't required to end with a slash. If one is there, it's ignored. DIRECTORY()supports UNC names.
lOutFileHere = FILE("OutPut.PRN")
lDirExists = DIRECTORY("C:\Temp")