I’m doing a production tool which copy files between folders in our pipeline, on Windows 10. My problem is that some files have been renamed with copy/paste by some people, and it seems to add illegal characters in the file names. Those characters are invisible in explorer.exe:
The illegals characters are between ‘0’ and ‘3’ (you should be able to cc them):
pixPath = u"E:/col_udim_test.1003.jpg"
os.rename and shutil.copy give errors when trying to handle the files:
os.rename(path + f, path + unicode(f))
WindowsError: [Error 123] La syntaxe du nom de fichier, de repertoire ou de volume est incorrecte
shutil.copy(path + f, path + 'test/' + unicode(f).replace('?', '')) with open(src, 'rb') as fsrc: IOError: [Errno 22] invalid mode ('rb') or filename: 'E:/col_udim_test.100?????3.jpg'
Trying to get hexa of illegal character n:
hex(ord(n)) gives me0x200b`
Anyone have an idea how to clean those file names? I was thinking about converting the unicode to hexa, remove unwanted hex and convert back to unicode,