Encoding of file names

Fredrik Lundh fredrik at pythonware.com
Thu Dec 8 11:48:04 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')

how did you print that name?  "\xa6" is a "broken vertical bar", which, as
far as I know, is a valid filename character under both Unix and Windows.

if DIR is a variable that points to the remote directory, what does this
print:

    import os
    files = os.listdir(DIR)
    file = files[0]
    print file
    print repr(file)
    fullname = os.path.join(DIR, file)
    print os.path.isfile(fullname)
    print os.path.isdir(fullname)

(if necessary, replace [0] with an index that corresponds to one of
the problematic filenames)

when you've tried that, try this variation (only the listdir line has
changed):

    import os
    files = os.listdir(unicode(DIR)) # <-- this line has changed
    file = files[0]
    print file
    print repr(file)
    fullname = os.path.join(DIR, file)
    print os.path.isfile(fullname)
    print os.path.isdir(fullname)

</F>






More information about the Python-list mailing list