PRB: File() Function Ignores Path if Given in Parameter (243542)



The information in this article applies to:

  • Microsoft Visual FoxPro for Windows 6.0

This article was previously published under Q243542

SYMPTOMS

The File() function documentation states that 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. Under certain conditions the File() function can return .t. even though the file does not exist in the path given in the parameter.

CAUSE

If the file exists along the Visual FoxPro path, the function returns .t..

RESOLUTION

Use the Adir() function. Supply the file name you are checking for as the second parameter in the Adir() function. The Adir() function returns 1 if the file is found.
nFilesFound=adir(atemp,"C:\temp.txt")
IF nFilesFound=1
     && Do processing on file
ELSE
     && File does not exist
ENDIF
				

MORE INFORMATION

Steps to Reproduce Behavior

Copy the following code into a file and run the program:
CLEAR
SET PATH TO
SET DEFAULT TO C:\ 
fh=FCREATE('C:\program files\testf.prg')
=FCLOSE(fh)
? FILE('C:\program files\testf.prg')
CD..
SET PATH TO 'program files'
? "Path="+SET('path')
? "default directory="+CURDIR()
? FILE('c:\testf.prg')
SET PATH TO
? FILE('C:\program files\testf.prg')
? FILE('C:\testf.prg')
DELETE FILE 'C:\program files\testf.prg'
? FILE('C:\testf.prg')
				

Modification Type:MajorLast Reviewed:10/27/1999
Keywords:kbCodeSnippet kbDSupport kbprb kbXBase KB243542