Encoding of file names

Peter Hansen peter at engcorp.com
Thu Dec 8 09:19:50 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.

I'm not sure of the answer, but note that .isfile() is not just checking 
whether the filename is valid, it's checking that something *exists* 
with that name, and that it is a file.  Big difference... at least in 
telling you where to look for the solution.  In this case, checking 
which of the two tests in ntpath.isfile() is actually failing might be a 
first step if you don't have some other lead.  (ntpath is what os.path 
translates into on Windows, so look for ntpath.py in the Python lib folder.)

If you're really seeing what you're seeing, I suspect a bug since if 
os.listdir() can find it (and it's really a file), os.isfile() should 
report it as a file, I would think.

-Peter




More information about the Python-list mailing list