
Ο χριστουγεννιάτικος στολισμός στο Ηράκλειο τους βγήκε λίγο... kinky (pics) | Plus: Viral | gazzetta.gr

Access denied | www.patrisnews.com used CloudFlare to restrict access

If you have a folder that contains thousands of files (in my case it was the motion daemon folder that contained thousands of pictures and videos from a surveillance camera) this script will organize them in sub folders named by the last modification date.
import os
import sys
import time
from datetime import datetime
import shutil
def orgbyday(directory):
ans=raw_input("Going to organize files in directory : " + directory + " by modification day in subfolders.Type 'y' to continue:")
if ans != 'y':
print 'exiting'
sys.exit(0)
print "listing dir: " + directory
l = [file for file in os.listdir(directory)
if os.path.isfile(os.path.join(directory, file)) ]
ilen = len(l)
slen = (str(ilen))
print "found " + slen + " files"
i=1
startt= time.time()
for f in l:
percent = (float(i) / float(ilen)) * 100.0
spercent = "%.2f" % percent
print str(i) + " of " + slen
print spercent + " % "
passed=time.time()-startt
remaining = (ilen - i) * (passed / i)
m, s = divmod(remaining, 60)
h, m = divmod(m, 60)
print "%d:%02d:%02d" % (h, m, s)
#print str(remaining)
print f
ff=os.path.join(directory,f)
mtime = os.path.getmtime(ff)
print "modified: %s" % time.ctime(mtime)
mdate = datetime.fromtimestamp(mtime)
creation_day = mdate.strftime('%Y-%m-%d')
subfolder = os.path.join(directory,creation_day )
dest = os.path.join(subfolder , f )
try:
shutil.move (ff , dest)
except:
os.mkdir(subfolder)
shutil.move (ff , dest)
print " "
print " "
print "\x1b[2J\x1b[H"
i +=1
if __name__ == '__main__':
orgbyday(sys.argv[1])