import os import sys import codecs import string def batch_rename(cfgname): # 获得目录下的所有文件 src_list = os.listdir("d:/picsample/picsample") print(src_list) # 获得路径 path = "d:/picsample/picsample" print('current path --' + path) # 改名 i = 0 for name in src_list: new_name = "test" + str(i) + ".jpg" i += 1 if new_name != none and i > 1: os.rename(os.path.join(path, name), os.path.join(path, new_name)) print(name + '-->' + new_name + " finish") else: print(name + ' not rename!') if __name__ == '__main__': batch_rename("d:/picsample/picsample")
0 条评论