快速批量修改文件名[机器学习]
import os
path = r'A:\Learning_OpenCV_3_Computer_Vision_with_Python_Second_Edition_Code\face_train'
filenames = os.listdir(path)
i = 1
for filename in filenames:
print(filename)
if os.path.isfile(os.path.join(path, filename)) == True:
new_name = filename.replace(filename, 'neg-%d.pgm' % i)
os.rename(os.path.join(path, filename), os.path.join(path, new_name))
i += 1
print('修改完毕......')
- path路径要提前创建好
- os.rename是完成修改的关键函数