Last active
February 19, 2024 01:26
-
-
Save austinyen56/81a58b93e4dcefd0b0da48d12b131a55 to your computer and use it in GitHub Desktop.
Photo and Video Sort
This file contains hidden or 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
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