By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,551 Members | 1,142 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,551 IT Pros & Developers. It's quick & easy.

How to copy files named with unicode characters?

P: 1
Expand|Select|Wrap|Line Numbers
  1. import shutil
  2.  
  3. files = os.listdir("C:\\")
  4. for efile in files:
  5.     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...
Nov 13 '10 #1
Share this Question
Share on Google+
1 Reply


bvdet
Expert Mod 2.5K+
P: 2,851
Try passing a unicode path to os.listdir().
Nov 13 '10 #2

Post your reply

Sign in to post your reply or Sign up for a free account.