"""
Created on Thu Aug 16 22:15:00 2018
@author: chenze
"""
import os
import shutil
import re
def mkdir(path):
folder = os.path.exists(path)
if not folder:
os.makedirs(path)
path='I:/data'
newpath='I:/data/ '
pathyear = os.listdir(path)
print(pathyear)
for ye in pathyear:
pathmonth = os.listdir(path+'/'+str(ye))
for mo in pathmonth:
pathday = os.listdir(path+'/'+str(ye)+'/'+str(mo))
old_path=path+'/'+str(ye)+'/'+str(mo)
print(old_path)
for da in pathday:
year = da[15:19]
month = da[19:21]
day = da[21:23]
new_dir=newpath+'/'+str(year)+' '+str(month)+' '+str(day)+' '
mkdir(new_dir)
new_path_files=os.path.join(new_dir,da)
old_path_files=os.path.join(old_path,da)
shutil.move(old_path_files, new_path_files)