Posted on

Nearly ten thousand files needed batch renaming. Their original names consisted of digits, Chinese characters, and an extension; I needed to extract the digits and extension to rename them.
I could not find a suitable tool online, so I wrote one myself. Since the task did not require complex features, I used cmd instead of regular expressions.

#-*-coding:utf-8-*-
import os
dir = raw_input('请输入路径')
while (os.path.isdir(dir)==False):
	print('路径不存在 请重新输入')
	dir = raw_input('请输入路径')
filelist=[]
filelist=os.listdir(dir)
n=0
for i in filelist:
	print i
	print n
	n+=1
	name0 = i
	name1 = name0[0:10]
	name2 = name0[-4:]
	name = name1 + name2
	os.system('move ' + dir + ''  + name0 + ' ' + dir+'' + name)


As a next step, using Python’s shutil module avoids the constant pop-up windows caused by the program above.

Leave a Reply