1、用python对一文件夹下
<文件名>
进行修改
文件名>
# -*- coding: utf-8 -*- import os #设定文件路径 path='G:\\whorl_nut\\' i=1 #对目录下的文件进行遍历 for file in os.listdir(path): #判断是否是文件 if os.path.isfile(os.path.join(path,file))==True: #设置新文件名 new_name=file.replace(file,"rgb_%d.jpg"%i) #重命名 os.rename(os.path.join(path,file),os.path.join(path,new_name)) i+=1 #结束 print ("End")
2、用python对一文件夹下
<文件夹名>
进行修改
文件夹名>
# -*- coding: utf-8 -*- import os #设定文件路径 path='C:\\Users\\admin\\Mask_RCNN\\cola1\\colatransfor\\' i=1 #对目录下的文件进行遍历 for category in os.listdir(path): #判断是否是文件 if os.path.isdir(os.path.join(path,category))==True: #设置新文件名 new_name=category.replace(category,"rgb_%d_json"%i) #重命名 os.rename(os.path.join(path,category),os.path.join(path,new_name)) i+=1 #结束 print ("End")
如有收获,感谢支持!
发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/206587.html原文链接:https://javaforall.net
