I’m trying to build a simple helper utility that will look through my projects and find and return the open ones to me via command line. But my calls to os.listdir return gibberish (example: '\x82\xa9\x82\xcc\x96I') whenever the folder or filename is in Japanese, and said gibberish can’t be passed to the call again to get into the folder either. i.e. os.listdir('C:\Documents and Settings\\x82\xa9\x82\xcc\x96I') returns an error:
'WindowsError: [Error 3] 指定されたパスが見つかりません。'
Does anybody know how I can get around this? Thanks a lot.
You may need to decode the string into Unicode, then re-encode it in UTF-8 before passing it to
os.listdir. It looks like your Japanese string is encoded in shift-JIS:Alternatively, make use of the following feature of
os.listdirto get Unicode strings out of it in the first place:So: