Skip to content

Instantly share code, notes, and snippets.

@wokoman
Created November 1, 2021 06:27
Show Gist options
  • Save wokoman/6f54f51b9a9eefbeb93841d6741fc615 to your computer and use it in GitHub Desktop.
Save wokoman/6f54f51b9a9eefbeb93841d6741fc615 to your computer and use it in GitHub Desktop.
Script to move photos into folder per their time-stamped name
"""
Simple script that moves files to folders accordingly to their name. Files must start with YYYYMM format.
Useful for old automatic media uploads by OneDrive iOS app (aka SkyDrive).
"""
import os
import shutil
from pathlib import Path
directory = '/path/to/files/'
for file in os.listdir(directory):
if "." in file:
Path(directory + str(file)[:4] + "/" + str(file)[4:6]).mkdir(parents=True, exist_ok=True)
shutil.move(directory + file, directory + str(file)[:4] + "/" + str(file)[4:6] + "/" + file)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment