OSX文件名中的特殊字符? (Python os.rename) [英] Special characters in OSX filename ? (Python os.rename)
问题描述
我试图使用python脚本在OSX上自动重命名一些文件。但是我无法使用正斜杠等特殊字符:
I am trying to rename some files automatically on OSX with a python script. But I fail to work with special characters like forward slash etc.:
oldname = "/test"
newname = "/test(1\/10)"
os.rename(oldname, newname)
我想我有一个编码问题。但是不同的尝试与re.escape或使用UTF-8 unicode编码没有成功为我。你有提示吗?
I think I do have an encoding problem. But different tries with re.escape or using UTF-8 unicode encodings havent been successful for me. Would you have a hint?
谢谢!
Marco
Thanks! Marco
推荐答案
大多数文件系统的共同点是它们不允许目录分隔符
What most of the file systems have in common is that they do not allow directory separators (slashes) in filenames.
也就是说,在Mac OS X中,您可以在finder中使用斜杠显示文件名 ,您可以尝试将斜杠替换为:
。
That said, in Mac OS X you can have file names appear with slashes in finder, you can try replacing slashes with :
.
这篇关于OSX文件名中的特殊字符? (Python os.rename)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!