Need to get 8.3 path on Windows
Michael Geary
Mike at DeleteThis.Geary.com
Sat Jan 17 02:40:11 EST 2004
Patrick L. Nolan wrote:
> Our python script uses popen to run an application on Windows XP.
> The application chokes if the filename given as a command line
> argument contains any spaces. It's happy with the 8.3 shortname
> notation, though. So given a file with a name like
> c:\Documents and Settings\Joe User\Desktop\My Files\foo.dat
> I would like to be able to convert this to
> c:\DOCUME~1\JOEUSE~1\Desktop\MYFILE~1\foo.dat
>
> This would be a fairly simple exercise in text manipulation
> except that the number may not always be 1. If the directory
> names are not unique in the first 6 characters, there may
> be ~2 etc.
You're looking for the Windows API function GetShortPathName, which is
supported by the win32api module in Mark Hammond's Windows extensions:
>>> import win32api
>>> win32api.GetShortPathName( "C:\Program Files\Internet Explorer" )
'C:\\PROGRA~1\\INTERN~1'
>>>
This function returns the actual short name for a file or directory; it
doesn't just do a string manipulation.
-Mike
More information about the Python-list
mailing list