Jason R. Coombs added the comment: I've confirmed the issue. It does indeed only occur if the string passed to rmtree is bytes. I discovered this during my investigation of https://github.com/cherrypy/cherrypy/issues/1467. The following script will replicate the failure on Windows systems on Python 2 and Python 3, but not on other operating systems:
--- # encoding: utf-8 from __future__ import unicode_literals import os import shutil os.mkdir('temp') with open('temp/Слава Україні.html', 'w'): pass print(os.listdir(b'temp')[0]) shutil.rmtree(b'temp') --- The error on Python 2.7 is this: ????? ???????.html Traceback (most recent call last): File "C:\Users\jaraco\p\cherrypy\issue-1467.py", line 15, in <module> shutil.rmtree(b'temp') File "C:\Program Files\Python27\lib\shutil.py", line 252, in rmtree onerror(os.remove, fullname, sys.exc_info()) File "C:\Program Files\Python27\lib\shutil.py", line 250, in rmtree os.remove(fullname) WindowsError: [Error 123] The filename, directory name, or volume label syntax is incorrect: 'temp\\????? ???????.html' This issue might be related to issue25911 or issue24230 or issue18713 or issue16656 or issue9820 and probably others. It's not obvious to me browsing through those tickets why Windows should behave differently when a bytestring is passed to listdir. Perhaps I'll delve into those tickets in more depth. ---------- nosy: +jason.coombs title: shutil.rmtree failes on non ascii filenames -> shutil.rmtree fails on non ascii filenames versions: +Python 3.5, Python 3.6 _______________________________________ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue24672> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com