Encoding of file names

Peter Otten __peter__ at web.de
Thu Dec 8 10:17:59 EST 2005


utabintarbo wrote:

> I am trying to programatically access files created on an IBM AIX
> system, stored on a Sun OS 5.8 fileserver, through a samba-mapped drive
> on a Win32 system. Not confused? OK, let's move on... ;-)
> 
> When I ask for an os.listdir() of a relevant directory, I get filenames
> with embedded escaped characters (ex.
> 'F07JS41C.04389525AA.UPR\xa6INR.E\xa6C-P.D11.081305.P2.KPF.model')
> which will read as "False" when applying an os.path.isfile() to it. I
> wish to apply some  operations to these files, but am unable, since
> python (on Win32, at least) does not recognize this as a valid
> filename.

Does the problem persist if you feed os.listdir() a unicode path?
This will cause listdir() to return unicode filenames which are less prone
to encoding confusion.

Peter



More information about the Python-list mailing list