Skip to content

Instantly share code, notes, and snippets.

@austinyen56
Last active February 19, 2024 01:26
Show Gist options
  • Save austinyen56/81a58b93e4dcefd0b0da48d12b131a55 to your computer and use it in GitHub Desktop.
Save austinyen56/81a58b93e4dcefd0b0da48d12b131a55 to your computer and use it in GitHub Desktop.
Photo and Video Sort
import os
from datetime import datetime
from tkinter import *
from tkinter.filedialog import askdirectory
import shutil
def photoSort():
path = askdirectory(title='Select your folder')
for i in os.listdir(path):
if i.endswith('.XML'):
os.remove(os.path.join(path, i))
print("Removed file: " + i)
continue
filetime = datetime.fromtimestamp(os.path.getmtime(os.path.join(path, i)))
month, date = filetime.strftime('%m %d').split()
if not os.path.exists(os.path.join(path, month + date)):
os.makedirs(os.path.join(path, month + date))
shutil.move(os.path.join(path, i), os.path.join(path, month + date))
print("Created folder: " + month + date)
print("Moved file: " + i, "to", month + date)
else:
shutil.move(os.path.join(path, i), os.path.join(path, month + date))
print("Moved file: " + i, "to", month + date)
photoSort()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment