Rick Strahl's Weblog
Rick Strahl's FoxPro and Web Connection Weblog
White Papers | Products | Message Board | News |

Fix up Paths with FULLPATH()


2 comments
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.

Posted in:

Feedback for this Weblog Entry


Re: Fix up Paths with FULLPATH()



E.R. Gilmore
June 18, 2007

That's cool! I didn't know fullpath would fix things like that. I usually wrap paths in addbs to be safe. Plus, it's just a fun function name. Maybe we need a similar abbreviated function name for add full url.

Re: Fix up Paths with FULLPATH()



William Plander
June 27, 2007

How 'bout that. It even does this one right.

? FullPath( "c:\test\pra\ac1..\adef1.dat")

To

C:\TEST\PRA\ADEF1.DAT

...not bad

 
© Rick Strahl, West Wind Technologies, 2003 - 2024