Python version: 2.7.3
Filename: test snowman character --☃--.mp3
Ran the following tests, None of them proved successful.
>>> os.path.exist('test snowman character --☃--.mp3')
False
>>> os.path.exist(repr('test snowman character --☃--.mp3'))
False
>>> os.path.isfile('test snowman character --\\xe2\\x98\\x83--.mp3')
False
>>> os.path.isfile(r'test snowman character --\\xe2\\x98\\x83--.mp3')
False
>>> os.path.isfile('test snowman character --☃--.mp3'.decode('utf-8'))
False
Tried to retrieve files with glob, even that test failed.
Objective is to detect and copy this file to another folder, Please Advise.
Use a unicode value; preferably with a unicode escape sequence:
os.path.isfile(u'test snowman character --\u2603--.mp3')
Python on Windows will use the correct Windows API for listing UTF16 files when you give it a unicode path.
For more information on how Python alters behaviour with unicode vs. bytestring file paths, see the Python Unicode HOWTO.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With