import os, time, shutil src_dir=os.getcwd() print("Working path:", src_dir) for filename in os.listdir(src_dir): mtime=time.strftime("Last modification: %b/%Y", time.localtime(os.path.getmtime(filename))) print("File:",filename,mtime) mtime_path=time.strftime("\\%Y\\%m", time.localtime(os.path.getmtime(filename))) dst_dir=os.getcwd()+mtime_path src_file=os.path.join(src_dir, filename) dst_file=os.path.join(dst_dir, filename) if not os.path.exists(dst_dir): os.makedirs(dst_dir) shutil.move(src_file, dst_file) print("Done.")