gpt4 book ai didi

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

转载 作者:太空宇宙 更新时间:2023-11-04 01:40:15 27 4
gpt4 key购买 nike

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

需要重命名的文件包含特殊字符组来代替重音字符。我制定了转换表 here . (无论如何,这里使用了什么样的编码?)

我猜测 perl 是该任务的最佳选择,但它也可能是 php/python/shell。有人会好心帮我写这样的脚本吗?

在此先感谢您的帮助。

最佳答案

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

关于Php/Perl/Python/Shell 脚本根据某些字符的存在重命名文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5877759/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com