Getting Unicode filenames in Windows 2000

Itamar Shtull-Trauring itamar at maxnm.com
Mon Feb 26 10:29:31 EST 2001


I have a file whose name is part Hebrew, part English on my W2K VMware
install. I'm running BeOpen Python 2.0, with the latest Pythonwin installed.

My problem - the os.listdir() command doesn't return the name of the file in
unicode, it just replaces the hebrew characters with question marks - '?':

>>> l = os.listdir("c:\\")
>>> l[-1]
'????.txt'
>>> type(l[-1])
<type 'string'>

1. How can I get the list of files in a directory in unicode? I would prefer
a cross-platform solution that doesn't use the win32 API.

2. If this behavior is because of backwards compatability, perhaps
os.listdir should be changed so that when passed strings it returns strings
and when passed a unicode string path it returns unicode strings?

-- 
Email: itamar at shtull-trauring.org
Web:   http://itamarst.org




More information about the Python-list mailing list