Python一括修正画像名

516 ワード

import os 
def rename():
	#      
	path = r'C:\Users\FEA\Desktop\1st\NG\G\4'
	#          
	filelist = os.listdir(path)
	a = 1
	for files in filelist:
		#     
		Olddir = os.path.join(path,files)
		
		#if os.path.isdir(Olddir):
		#	continue
		#      ,   xxx.bmp   xxx .bmp
		#xxx
		filename = os.path.splitext(files)[0]
		#.bmp
		filetype = os.path.splitext(files)[1]
		#        a            
		Newdir=os.path.join(path,str(a)+filetype)
		os.rename(Olddir,Newdir)
		a += 1
rename()