Unicode to DOS filenames (to call FSUM.exe)

Christian Stooker durumdara at mailpont.hu
Mon May 15 03:45:50 EDT 2006


Hi !

Yesterday I got a very interesting bug.
I don't understand, why I got it, because I thinking about this 
function: that is safe.
But I was not.

The code:

import sys,os

UFN=u'%s\\xA\xff'%os.getcwd()
if os.path.exists(UFN):
    os.remove(UFN)

f=open(UFN,'w')
f.write('%s\n'%('='*80))
f.close()

import win32api
dfn=win32api.GetShortPathName(UFN)

sys.exit()
###################################################
Commandline: C:\Python24\python.exe G:\SPEEDT~1\Module1.py
Workingdirectory: G:\speedtest
Timeout: 0 ms

Traceback (most recent call last):
  File "G:\SPEEDT~1\Module1.py", line 14, in ?
    dfn=win32api.GetShortPathName(UFN)
UnicodeEncodeError: 'ascii' codec can't encode character u'\xff' in 
position 15: ordinal not in range(128)

Process "Pyhton Interpeter" terminated, ExitCode: 00000001
###################################################


I want to get the sorter file name to pass it the FSUM.exe. But I got 
this error in every machine.
How to I avoid this error ? I need very safe code for my program.

Thanx for help:
dd





More information about the Python-list mailing list