Hacker’s Guide to Visual FoxPro
An irreverent look at how Visual FoxPro really works. Tells you the inside scoop on every command, function, property, event and method of Visual FoxPro.
DISPLAYPATH()
Ever needed to show a long path in a short space? That’s what this function is all about. It was added in VFP 7.
cShortPath = DISPLAYPATH( cFileName, nMaxChars )
Sometimes you need to show the user a filename with a path, but the amount of space you have is limited. With long file and directory names, this comes up even more than it used to. So, what’s the solution? The Windows answer is to replace some portion of the path with an ellipsis (“…” which is made of three periods, as opposed to CHR(188) in the Symbol font), making sure not to break up any directory names. Now, you too can do it this way.
Pass a filename and the number of characters you have to display it to the function, and it finds a reasonable place to pull out some of the less relevant pathing information. Obviously, the larger the second parameter, the more information you keep.
The return value of this function is suitable only for display. It’s not the DOS 8.3 path to the file, and trying to use it in a file handling command or function is likely to give bad results.
nMaxChars must be at least 10; it maxes out at 256. Values below 10 or over 256 fire error 11 (“Function argument value, type or count is invalid”).
The return value of DisplayPath() is always lowercase, regardless of the original case of the path. Given that this function is designed for creating displayable paths, this is a particularly glaring error. |
* These results come from Tamar's Windows 2000 machine
? DisplayPath( HOME(7), 30 )
&& "c:\...\visual foxpro\"
? DisplayPath( HOME(7), 40 )
&& "c:\...\microsoft\visual foxpro\"
? DisplayPath( HOME(7), 60 )
&& "c:\...\tamar\application data\microsoft\visual foxpro\"
? DisplayPath( HOME(7), 70 )
&& "c:\...\tamar\application data\microsoft\visual foxpro\"
? DisplayPath( HOME(7), 80 )
&& "c:\documents and settings\tamar\application data\microsoft\visual foxpro\"