python 文件重命名
#coding=utf-8
import os
import string
num = 1
path = raw_input("Input the path:")
if '' == path:
path = os.getcwd()
if not os.path.exists(path):
print 'Path not exist!'
else:
for root, dirs, files in os.walk(path):
for pre_name in files:
if pre_name == '.DS_Store':
continue
#new_name = pre_name.replace('\n','').replace(':', '')
new_name = 'pic'+str(num)+'.jpg'
pre_full_name = os.path.join(root, pre_name)
new_full_name = os.path.join(root, new_name)
# I should backup all the files before rename
os.rename(pre_full_name, new_full_name)
print 'Rename from: ' + pre_name + ' to: ' + new_name
num = num + 1
print 'Rename all done!'
本文使用Blog_Backup未注册版本导出,请到soft.pt42.com注册。

浙公网安备 33010602011771号