import os
import re
"""批量修改文件夹下图片名称"""
def FileName(dirPath, pattern):
"""
:param dirPath: 修改的文件夹路径
"""
# 对目录下的文件进行遍历
i = 1
for file in os.listdir(dirPath):
# 判断是否是文件
if os.path.isfile(os.path.join(dirPath, file)) == True:
#c= os.path.basename(file)
newName = re.sub(pattern, str(i)+'.jpg', file)
newFilename = file.replace(file, newName)
# 重命名
os.rename(os.path.join(dirPath, file), os.path.join(dirPath, newFilename))
i+=1
print("修改完成")
if __name__ == '__main__':
dirPath = r"D:\cyclegan\datasets\pump2top\trainA"
pattern = re.compile(r'.*')
ReFileName(dirPath,pattern)
python批量修改图片名称
最新推荐文章于 2022-08-24 21:28:54 发布