import os, shutil
os.chdir('D:/00-test')
ori_path=os.getcwd()
newdoc='./pic'
if os.path.exists(newdoc):
print('Already exist')
else:
os.mkdir(newdoc)
print('Created')
try:
id=0
for file in os.listdir(ori_path):
id+=1
if os.path.isfile(file) and (os.path.splitext(file))[1]=='.jpg':
os.rename(file,str(id)+(os.path.splitext(file))[1])
newname=str(id)+(os.path.splitext(file))[1]
shutil.move(os.path.join(ori_path,newname),'./pic')
with open('log.txt', 'a') as f:
f.write('%s ----Change---- to %s
' % (file,newname))
except Exception as e:
print (e)
finally:
print('Finish')