Skip to content

Instantly share code, notes, and snippets.

@vadviktor
Created August 30, 2012 14:28
Show Gist options
  • Star 10 You must be signed in to star a gist
  • Fork 9 You must be signed in to fork a gist
  • Save vadviktor/3529628 to your computer and use it in GitHub Desktop.
Save vadviktor/3529628 to your computer and use it in GitHub Desktop.
Python: move files to creation date named directories
#!/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)
@master-elodin
Copy link

This was very useful for sorting pictures. Thanks! I just had to add some + signs in the strings

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment