基于特定字符存在重命名文件的Php/Perl/Python/Shell脚本
在CentOS 5.6系统中,我需要递归地重命名一系列位于/path目录下的文件。
这些需要重命名的文件里包含了一些特殊字符,代替了带重音的字符。我已经整理了一张转换表,具体内容可以在这里查看。(顺便问一下,这里用的是什么编码呢?)
我猜用perl来完成这个任务可能是最好的选择,但也可以用php、python或者shell。有没有人愿意帮我写一个这样的脚本呢?
提前感谢任何帮助。
1 个回答
3
这是因为UTF-8编码出错了。你可以使用 convmv
工具来解决这个问题。
>>> print u'Ó'.encode('cp1252').decode('utf-8').encode('cp1252').decode('utf-8')
Ó
$ convmv --nosmart -f utf-8 -t cp1252 Ó
Starting a dry run without changes...
mv "./Ó" "./Ó"
Ó exists and differs or --replace option missing - skipped
No changes to your files done. Use --notest to finally rename the files.
$ convmv --nosmart -f utf-8 -t cp1252 Ó
Starting a dry run without changes...
mv "./Ó" "./Ó"
No changes to your files done. Use --notest to finally rename the files.