Created
February 9, 2017 07:47
-
-
Save kepsic/c951f62ade93e635708eefaa8fe479ca to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
import os,shutil | |
import datetime | |
path=os.path.expanduser('~') | |
archdir='archive' | |
exclude=[archdir, '.ssh', '.vimrc', '.hgrc', 'tmp','.viminfo',os.path.basename(__file__)] | |
cwd = os.getcwd() | |
if not os.path.isdir(path+'/'+archdir): | |
os.makedirs(path+'/'+archdir) | |
for item in os.listdir(path): | |
try: | |
if item not in exclude: | |
filename=path+'/'+item | |
stat=os.stat(filename) | |
ctime=datetime.datetime.fromtimestamp( | |
stat.st_ctime | |
).strftime('%Y-%m-%d %H:%M:%S') | |
cyear=datetime.datetime.fromtimestamp( | |
stat.st_ctime | |
).strftime('%Y') | |
#print("file: %s\nstat: %s\nctime:%s" % (filename,stat,ctime)) | |
dst=cwd+'/'+cyear | |
if not os.path.isdir(dst): | |
os.makedirs(dst) | |
print("Moving %s (ctime %s) to %s" % (filename,ctime,dst)) | |
shutil.move(filename,dst) | |
except Exception as e: | |
print(e) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment