import os
def rename():
count = 0
path="./dataset/val/Abnormal/"
filelist=os.listdir(path)#该文件夹下所有的文件(包括文件夹)
for files in filelist:#遍历所有文件
Olddir=os.path.join(path,files)#原来的文件路径
if os.path.isdir(Olddir):#如果是文件夹则跳过
continue
#filename=os.path.splitext(files)[0]#文件名
filetype=os.path.splitext(files)[1]#文件扩展名
Newdir=os.path.join(path,str(count)+'_0''.JPG')#新的文件路径
filename = os.path.split(path)
os.rename(Olddir,Newdir)#重命名
#f = open('./abnormaltxt.txt','a')
# (filepath, tempfilename) = os.path.split(Newdir)
#f.write(tempfilename + ' ' + '1'+'\n')
#f.close()
count+=1
rename()
为文件夹的图片重新命名filename_label的形式
最新推荐文章于 2021-08-03 13:33:22 发布