So what I'm trying to do is fix some id3tags of mp3 files. It all works, except for files with any kind of accent, because os.walk seems to strip them.
For example, I have the file 01.Co Słychać.mp3
, which in this code:
for root, dirs, files in os.walk(folder):
print files
Shows up as ['01.Co Slychac.mp3']
, later resulting in a 'No such file or directory' error.
How can this开发者_开发百科 be fixed?
Did you define folder
as a Unicode string? This has implications on how os.walk()
matches its subdirectories, or better, the type of string that it returns.
>>> for a,b,c in os.walk("."):
... print b
... break
...
['DLLs', 'Doc', 'include', 'Lib', 'libs', 'tcl', 'Tools']
>>> for a,b,c in os.walk(u"."):
... print b
... break
...
[u'DLLs', u'Doc', u'include', u'Lib', u'libs', u'tcl', u'Tools']
精彩评论