Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
VFP6: Long directory names
Message
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Divers
Thread ID:
00827457
Message ID:
00827528
Vues:
23
Do you want the short path? Try this.
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))
endif
FYI, 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.
Examples of inconsistent handling
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 path
HTH

Elmer



>No, the problem is that I have a directory name field of 52 character and Windows allows for 255 characters. I want to shrink the long directory name into the 52 character field. VFP7+ have a displaypath() function that does what I need but I need it in VFP6. Thanks!
>
>
>>Does this work for you?
>>
>>?getdir()
>>or
>>?addbs(justpath(getfile()))
>>
>>
>>>I am looking for a way to display long directory names in VFP6. I am sure you have seen in Windows the directory name with ellipsis to shrink the name. Any ideas?
>>>TIA!
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform