Last active
March 25, 2021 21:35
-
-
Save tpokorra/c5f340c03f9f3fc3250ac8a6b24794fa to your computer and use it in GitHub Desktop.
Arrange Photos into directories per day
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/python3 | |
import os | |
import pathlib | |
from datetime import datetime | |
for file in os.listdir("."): | |
if file.endswith(".jpg") or file.endswith(".3gp"): | |
if '_' in file: | |
date = datetime.strptime(file.split("_", 2)[1], '%Y%m%d') | |
datestr = date.strftime('%m/%d/%Y') | |
print(file + " " + datestr) | |
directory = os.path.join(os.getcwd(), date.strftime('%Y') + "-" + date.strftime('%m') + "-" + date.strftime('%d')) | |
if not os.path.exists(directory): | |
os.makedirs(directory) | |
os.rename (os.path.join(os.getcwd(), file), os.path.join(directory, file)) | |
for file in os.listdir("."): | |
if file.endswith(".JPG") or file.endswith(".jpg") or file.endswith(".3gp"): | |
fname = pathlib.Path(file) | |
date = datetime.fromtimestamp(fname.stat().st_mtime) | |
datestr = date.strftime('%m/%d/%Y') | |
print(file + " " + datestr) | |
directory = os.path.join(os.getcwd(), date.strftime('%Y') + "-" + date.strftime('%m') + "-" + date.strftime('%d')) | |
if not os.path.exists(directory): | |
os.makedirs(directory) | |
os.rename (os.path.join(os.getcwd(), file), os.path.join(directory, file)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment