FullPath(), Sys(2014)

These two functions let you retrieve file paths. FULLPATH() gives you the complete path to a file while SYS(2014) lets you find a relative path between a file and a directory. Both return spurious information about nonexistent files, so you have to check up on them.

Usage

cAbsolutePath = FULLPATH( cFileName 
                          [, nUseDOSPath | cBaseFile ] )
cRelativePath = SYS( 2014, cFileName [, cBasePath ] )

Parameter

Value

Meaning

cFileName

Character

The name of the file whose path you want.

nUseDOSPath

Numeric

Look all along the DOS path to find cFileName.

Omitted

If cBaseFile is also omitted, look all along the FoxPro path to find cFileName.

cBaseFile

Character

Use the location of cBaseFile as the location from which to do relative addressing.

Omitted

If nUseDOSPath is also omitted, look all along the FoxPro path to find cFileName.

cBasePath

Character

Find the minimum path to cFileName from cBasePath.

Omitted

Find the minimum path to cFileName from the default directory.


These two functions do related, yet nearly opposite, things. FULLPATH() takes a pathless or relatively pathed file and returns the absolute path to it. SYS(2014) takes a pathless or absolutely pathed file and returns a relative path to it.What do we mean by absolute and relative paths? An absolute path is one where the exact directory names are hard-coded—for example, C:\WINDOWS\SYSTEM. A relative path uses the DOS directory shortcuts (especially ".." for "parent of current directory") to provide directions from one place to another. For example, if you're in Visual FoxPro's TOOLS\ADDLABEL directory, you can find Filer.DLL in ..\FILER. It doesn't matter what the name of the Visual FoxPro directory is or on what drive. As long as the directory tree is the one FoxPro installed, the relative path above will find the Filer library.Within an application, you generally want to use relative paths, so you can install the application in any directory and still have it find its files. Most of Visual FoxPro's metadata tables (SCX, PJX, and so on) store relative paths whenever possible. But there are times (like for reporting) when you need to know the absolute path to a file. That's where FULLPATH() comes in. Similarly, when you're writing developer tools and other things that store paths, you'll want to convert from an absolute path to a relative path—enter SYS(2014).If you pass FULLPATH() only cFileName, FoxPro searches the current FoxPro path (created with FoxPro's SET PATH) and returns an absolute reference to the named file. If you pass the optional numeric parameter, it does the same thing, except it uses the DOS path (set in DOS' PATH environment variable) rather than the FoxPro path. If cFileName includes relative references, they're converted to absolute. When you add the optional character parameter, things get interesting. The relative references are converted with respect to the file you pass.SYS(2014) goes the other way. Hand it a filename and a directory and it returns the shortest path from that directory to the file. Whenever possible, it makes the references relative, using the .. notation.Be careful with the second parameter. If you omit the final "\", FoxPro assumes you've simply added a filename at the end and works from a directory one level higher than you meant.

Under Win32s, FoxPro gets horribly confused if you omit the third parameter to SYS(2014) and specify an absolute path on the current drive for the file. The path returned includes far too many references to the parent directory. You could climb all the way to the root and then some. Of course, this is a problem only for VFP 3 running under Windows 3.1, since VFP 5 and later don't run in Win32s.


 

Both these functions will mislead you if you specify a file that doesn't exist. They return a path to the specified filename and don't bother to tell you it's not really there. With FULLPATH(), you're safe as long as the file exists somewhere on the path (either FoxPro or DOS, depending on the second parameter). SYS(2014) gives back really weird paths, but they amount to pointing to the nonexistent file in the current directory. The bottom line is that you can't count on either of these to make sure the file is there. Check with FILE() before you try to use it.


Example

* Assume Visual FoxPro is installed in F:\VFP
CD F:\VFP\SAMPLES
SET PATH TO TASTRADE, TASTRADE\DATA
* Search on FoxPro path
? FULLPATH("TasTrade.DBC")
* Returns "F:\VFP\SAMPLES\TASTRADE\DATA\TASTRADE.DBC"
 
* Search DOS path
? FULLPATH("Win.ini",1)&& Returns "C:\WINDOWS\WIN.INI"
 
* You can use FULLPATH() to find the location of a table
* in a DBC (which ADBOBJECTS() doesn't give you)
OPEN DATA TasTrade
? FULLPATH(DBGETPROP("customer","table","path"),DBC())
* Returns "F:\VFP\SAMPLES\TASTRADE\DATA\CUSTOMER.DBF"
 
SET PATH TO 
 
* Use SYS(2014) for relative paths
CD F:\VFP\SAMPLES\TASTRADE
? SYS(2014,"\VFP\VFP.EXE",CURDIR()) && Returns "..\..\VFP.EXE"
? SYS(2014,"F:\VFP\TOOLS\FOXTOOLS.CHM", ;
     "F:\VFP\GALLERY\FAVORITES.DBF")
* Returns "..\TOOLS\FOXTOOLS.CHM"
 
* Now here's the absurd case demonstrating the bug in Win32s.
* This example gives these results only in VFP 3 under Win3.1
? SYS(2014,"\VFP\SAMPLES\CONTROLS\CANCEL.BMP")
* Returns "..\..\..\..\CONTROLS\CANCEL.BMP"

See Also

ChDir, CurDir(), Set Default, Set Path


Back to Table of Contents

Copyright © 2002-2018 by Tamar E. Granor, Ted Roche, Doug Hennig, and Della Martin. Click for license .