# -*- coding:utf-8 -*-
import os from xpinyin import Pinyin test = Pinyin() def get_name(): path = r"D:picsxpinyin_tb" for filename in os.listdir(r"D:picsxpinyin_tb"): #listdir的参数是文件夹的路径 print ( filename) old_dir = os.path.join(path,filename) new_name = ''.join(test.get_pinyin(filename).split('-')).replace(".png",".jpg") print(new_name) new_dir = os.path.join('D:picsxpinyin_tb',new_name) print(new_dir) os.rename(old_dir,new_dir) if __name__ == '__main__': get_name()