Menu

#610 GetShortPathName() fails for 8.3 baltic file names

closed-invalid
nobody
win32 (141)
5
2012-09-04
2012-09-03
Anonymous
No

If a 8.3 file name containing at least one baltic character is given to GetShortPathName(), it fails with exception. It does not fails on long file names:

Traceback (most recent call last):
File "D:\workspace\investigations\audio-hash\invest\GetShortName-bug\bug.py", line 10, in <module>
print win32api.GetShortPathName(file)
File "C:\Python\27\lib\encodings\cp866.py", line 12, in encode
return codecs.charmap_encode(input,errors,encoding_map)
UnicodeEncodeError: 'charmap' codec can't encode character u'\xf5' in position 2: character maps to <undefined>

õ2345678.txt <-- does fail
õ23456789.txt <--- does not

See a file attached.

Python 2.7.3, Russian WIndows 7 32 bit, PyWin32 ver. 217

Discussion

  • Mark Hammond

    Mark Hammond - 2012-09-04

    It appears the problem here is actually with "print" attempting to use the cp866 encoding when printing to your terminal. GetShortPathName returns the same type of object as its param (eg, if you pass a byte string, it returns a byte string) and this string is failing to print as it isn't encoded as cp866 (it will be encoded as MBCS).

    You can confirm this by changing your code to something like:

    x = win32api.GetShortPathName(file)
    print x

    you should then see clearly the exception is from the print, not from win32api. Probably the best solution is just to ensure "file" is a unicode object before passing it to win32api.GetShortPathName. Please reopen this bug and add further information if you believe this is not the case.

     
  • Mark Hammond

    Mark Hammond - 2012-09-04
    • status: open --> closed-invalid