Wiki Home

Short Path


Namespace: WIN_COM_API
************************************************************************
FUNCTION ShortPath
******************
*** Function: Converts a Long Windows filename into a short
*** 8.3 compliant path/filename
*** Pass: lcPath - Path to check
*** Return: lcShortFileName
*************************************************************************
LPARAMETER tcPath

DECLARE INTEGER GetShortPathName IN Win32API;
STRING @lpszLongPath, STRING @lpszShortPath,;
INTEGER cchBuffer

lcPath = tcPath
lcshortname = SPACE(260)
lnlength = LEN(lcshortname)
lnresult = GetShortPathName(@lcPath, @lcshortname, lnlength)
IF lnResult = 0
RETURN ""
ENDIF
RETURN LEFT(lcShortName,lnResult)


The code or function (above) does not mention the not-so-obvious that if the file does not exist then 'lnResult' will be 0 and the function will return an empty string.

Get Short Path NameOffsite link to http://www.news2news.com/vfp/?function=83
absolutely needs a file that already exists.

This will be a problem if you are using this API function to create a DOS 8.3 name for a filename that does not yet exist, but that will later or might be the destination file.

In my 'Gotcha' scenario I was calling this function as above in order to on-the-fly create a BAT file that would create files. To make a long story short, the whole thing blew up in my face because what were long name files and paths (e.g. 'Documents and Settings' like the Temp folder in 'Local Settings') got emptied out when lnResult was 0.

For example and a strange example:

lcTempFile = home(0) + 'myfile That Does Not Exist Yet.txt'
lcCmd = '!mybat.bat > ' + Short Path(lcTempFile)
&lcCmd

lcCmd will end up as: '!mybat.bat > '

And that's not what you want.

JeffL

Category Windows API Category Code Samples
( Topic last updated: 2005.05.17 01:03:21 AM )