Pythonでファイル名を一括変更


用Python批量修改文件名_第1张图片
作者:金良([email protected])csdnブログ:http://blog.csdn.net/u012176591
現在のディレクトリの下のファイルヒットで指定した中国語の内容を対応する英語文字で置き換えます.
import os

namepre = ['  ','  ','  ','  ',
            '  ','  ','  ','  ','  ','  ','  ','  ']
namepost = ['fi','lo','co','ed',
            'te','ca','ta','sp','he','ar','fu','ho']

files = os.listdir('.')

for file in files:
    if file.endswith('.txt'):
        for pre in namepre:
            if file.startswith(pre):
                i = namepre.index(pre)
                os.rename(file, file.replace(pre,namepost[i]))

効果は次のとおりです:用Python批量修改文件名_第2张图片