function api_getshortpath lparameters m.lcLongFile,m.llReturnShortFilename *!* first parameter = filename with full path *!* any second parameter returns shortpath and 8.3 filename *!* only one parameter returns just short path without filename m.lcLongFile = iif(type("m.lcLongFile") <> "C" or empty(m.lcLongFile),getfile(),m.lcLongFile) if empty(m.lcLongFile) return "" endif m.lcBuffer = SPACE(511) m.lnBufferSize = 511 DECLARE INTEGER GetShortPathName IN Win32API ; STRING @cLongPath, ; STRING @cShortPathBuff, ; INTEGER nBuffSize m.lnShortPathLen = GetShortPathName(m.lcLongFile, @m.lcBuffer, @m.lnBufferSize) m.lcShortPath = strtran(LEFT(m.lcBuffer, m.lnBufferSize),chr(0),"") if pcount() > 1 return m.lcShortPath else return left(m.lcShortPath,rat("\",m.lcShortPath)) endifFYI, one problem that I have found with this is that some VFP commands do not handle short paths very well or at least there is some inconsistency in how they handle it.
use (api_getshortpath(getfile("dbf"),.t.)) && errors with invalid path or filename Modify file (api_getshortpath(getfile("txt"),.t.)) && errors with invalid path ?File(api_getshortpath(getfile("txt"),.t.)) && returns .f. but file exists ?adir(laFilelist,api_getshortpath(getfile("txt"))+"*.*") && loads array with list of files as expected ?directory(api_getshortpath(getfile("txt"))) && returns .t. as expected m.lcNewPath = api_getshortpath(getfile("txt")) cd (m.lcNewPath) && changes default directory as expected but sys(2003) return new short pathHTH