new scripts

This commit is contained in:
2021-03-24 11:50:44 -04:00
parent 2af3e608f7
commit 1a2773ac76
5 changed files with 62 additions and 18 deletions

20
scripts/sort-by-time.py Normal file
View File

@@ -0,0 +1,20 @@
import os
import sys
import pathlib
import datetime
dirn = sys.argv[1]
dirlist = os.listdir(dirn)
dates = []
for f in dirlist:
if f[:1] != '.' and os.path.isfile(dirn + "/" + f):
fname = pathlib.Path(dirn + "/" + f)
ctime = datetime.datetime.fromtimestamp(fname.stat().st_ctime)
date = str(ctime)[:10]
if date not in dates:
if not os.path.isdir(dirn + "/" + date):
dates.append(date)
os.mkdir(dirn + "/" + date)
os.rename(dirn + "/" + f, dirn + "/" + date + "/" + f)