Php / Perl / Python / Shell脚本根据某些字符的存在重命名文件

时间:2022-06-19 10:32:38

in centOS 5.6, i need to recursively rename a series of files in /path.

在centOS 5.6中,我需要递归重命名/ path中的一系列文件。

the files that need to be renamed contain groups of special characters in lieu of accented chars. i mapped out the table for conversion here. (What kind of encoding was used here anyways?)

需要重命名的文件包含特殊字符组,而不是重音字符。我在这里列出了转换表。 (这里使用了什么样的编码?)

i have a guess that perl would be best choice for the task, but it could also be php/python/shell. would someone be kind enough to help me with such script?

我猜测perl将是该任务的最佳选择,但它也可能是php / python / shell。有人会善意帮助我这样的剧本吗?

thanks in advance for any help.

提前感谢您的帮助。

1 个解决方案

#1


3  

That's mis-encoded UTF-8. Use convmv for that.

那是错误编码的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.

#1


3  

That's mis-encoded UTF-8. Use convmv for that.

那是错误编码的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.