[python-win32] Try to got short path for files - but goterror...
Metz, Bobby W, WWCS
bwmetz at att.com
Thu May 25 03:01:07 CEST 2006
FYI,
looking around a bit on Google it appears this question has been
posted before without a clear answer...in fact, lots of places without
clear answers. One guy went so far as to "cheat" as he put and used
WSH. But that's not much better than my "cheat". So, aside from Mark's
short code request, I'd suggest spending some more time with Google.
Mark,
Do you know if it's possible to get all the usual "right-click"
file properties using win32com or ctypes? I know Windows presents short
names via properties, but wasn't sure that's exposed via either. I
googled this but didn't see a clear direction after the first 50 hits.
May be a bad search on my part.
Bobby
-----Original Message-----
From: python-win32-bounces at python.org
[mailto:python-win32-bounces at python.org] On Behalf Of Mark Hammond
Sent: Wednesday, May 24, 2006 4:03 PM
To: DurumDara; python-win32 at python.org
Subject: Re: [python-win32] Try to got short path for files - but
goterror...
I'm afraid your message isn't very clear. You should try and copy the
smallest possible code that demonstrates your problem, exactly as Bobby
did
in his reply.
>
> I got errors with unicode file names. See my unicode test file name:
> UFN=u'%s\\xA\xff'%os.getcwd()
Is that what you mean? You have a literal backslash, followed by 'xa',
followed by unicode char ff. Eg:
>>> u'%s\\xA\xff'%os.getcwd()
u'c:\\src\\xA\xff'
>>>
The 'xA' is *not* a unicode char in your example.
> I want to get an universal code the convert (unicode) long path to
short
> path.
There is no way you can do that. Windows allocates the short name for a
file as it is created. That short name is not guaranteed to be the same
on
2 different machines. The only way to get the short name is to ask
Windows
for it.
> >> Looks like you need a GetShortPathNameW() but it's not
implemented.
> >> Raise it as an issue on the pywin32 sourceforge bug register.
> >> Tell Mark
> >> I sent you :-)
> >> Another thought: try using ctypes.
Note that Windows uses MBCS encoding - so you can use
win32api.GetShortPathName(filename).decode('mbcs') to get the unicode
filename. That only works if the unicode characters are all in your
current
codepage, but that is usually the case. GetShortPathName does need
upgrading to accept a unicode object and in that case call
GetShortPathNameW.
Cheers,
Mark
_______________________________________________
Python-win32 mailing list
Python-win32 at python.org
http://mail.python.org/mailman/listinfo/python-win32
More information about the Python-win32
mailing list