Fix up Paths with FULLPATH()
June 15, 2007 •
In many application it’s common to have to deal with building paths on the fly. You combine paths or deal with paths from multiple files or even - as I do often – you need to consolidate paths between Web logical paths and physical disk paths.
One thing that is a common issue in Visual FoxPro is that the various path functions in VFP return file paths with inconsistent trailing slashes. For example, CURDIR() returns with a final slash, SYS(2023) (which gets the temporary folder) on the other hand does not and neither does JUSTPATH()
? SYS(5) + CURDIR()
? SYS(2023)
? JUSTPATH("c:\temp\test.txt")
So here’s something that I didn’t realize until today – FoxPro’s FULLPATH() is a great tool for fixing up paths and normalizing backslashes properly. While you still have to pay attention to making sure you don’t completely miss a backslash, FULLPATH() can make sure your backslashes are in the right direction and quantity (1 <s>).
For example, FULLPATH will perfectly clean up this mess:
? LOWER(FULLPATH("c:/temp\\\mine/test.prg"))
Not exactly rocket science but it does make life simpler in certain situations.
For example, in most of my applications I use configuration files to hold paths that users may modify and you can bet your butt that there will be inconsistencies in how those paths are entered. FULLPATH() can make short work of that though.
E.R. Gilmore
June 18, 2007