Created
February 4, 2020 17:43
-
-
Save wbhinton/eeb47d7cbe536d5f85a92b16b416f87f to your computer and use it in GitHub Desktop.
Reorganize files by creation date
This file contains hidden or 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/python3 | |
import os, time, shutil, sys | |
dir = sys.argv[1] | |
os.chdir(dir) | |
for f in os.listdir('.'): | |
ftime = time.gmtime(os.path.getmtime(f)) | |
ctime_dir = str(ftime.tm_year) '-' str(ftime.tm_mon) '-' str(ftime.tm_mday) | |
if not os.path.isdir(ctime_dir): | |
os.mkdir(ctime_dir) | |
dst = ctime_dir '/' f | |
shutil.move(f, dst); | |
print('File' f 'has been moved to' dst) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment