How to copy files named with unicode characters?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • hadiyazdi
    New Member
    • Nov 2010
    • 1

    How to copy files named with unicode characters?

    Code:
    import shutil
    
    files = os.listdir("C:\\")
    for efile in files:
        shutil.copy(efile, "D:\\")
    I didn't think this simple script may crash whenever C: and D: are available and permissions are given, until I ran it on a pc with files named with unicode characters!

    Python converted these characters into question marks "????" when it got the list from os.listdir, and the copy process raised an exception...

    Any solution?!

    Thanks in advance...
  • bvdet
    Recognized Expert Specialist
    • Oct 2006
    • 2851

    #2
    Try passing a unicode path to os.listdir().

    Comment

    Working...