Detecting filename-encoding (on WinXP)?

Magnus Lycka lycka at carmen.se
Thu Feb 2 11:46:03 EST 2006


Tim N. van der Leeuw wrote:
> Hi,
> 
> I have a need to store directory and filenames in a database. For the
> database I chose to use UTF-8 encoding; but the actual encoding used is
> probably immaterial: whichever coding I take, I'll run into this issue
> eventually.
> 
> At first my code worked until I ran into a directory full of Cyrillic
> characters and my program blew up.

How did you find the files? Did you pass a Unicode path as argument
to os.listdir()? See http://www.python.org/peps/pep-0277.html

> So now what I need to know is, how do I find out in what encoding a
> particular filename is? Is there a portable way for doing this? And if
> not, then what is the non-portable way for doing this on Windows?
> (WinXP)
> (If there's only a non-portable way then I'll worry about porting it
> later, if and when this program will ever have a need to run on a
> Unix-like environment)




More information about the Python-list mailing list