Sort photos from a bulk folder into subfolders by date, first by year, then by month.
Sort either locally on disk, or on OneDrive, using Microsoft's Graph API.
Disclaimer: Like all publicly available code on the internet, use at your own risk. Inspect all code befor running. I'm not responsible if you accidentally delete all your photos, or if your computer explodes.
I use OneDrive as my cloud storage solution. Microsoft offers a phone app which you can use to back up your Camera Roll. For years, this would back up every photo into just one folder. Recently, an option was added to back up new photos sorted into folders by year and month. This is great for the new photos I take, but I still have thousands of old photos still in one folder. This program aims to sort all those old photos into subfolders, just like the new ones.
As mentioned in the disclaimer, this software is presented AS-IS, and you alone are responsible for any problems you encounter. That being said, here are some safety considerations:
- Sortation is done locally, on your machine, and there is only communcation with OneDrive. At the risk of stating the obvious, none of your personal data is sent to me.
- When finished, you should delete
token.txt
, since that contains a Microsoft Graph access token. It will expire after a few hours, but it should be deleted to be sure. - When finished, you should remove any app registrations in the Azure Active Directory. This way, no one can access your information if they obtain the app client ID
- Keep your client ID and tenant ID secret
Steps 6 and 7 can be omitted if you are just sorting files locally
- Ensure python 3 is installed
- Clone the repository, or download the source code from the latest release
- Create a new virtual environment in the source folder and activate it
- Install dependencies by running:
pip install -r requirements.txt
- Install the module by runnning
pip install .
- Register the app on Microsoft Graph (see Microsoft Registration)
- Paste the Client ID and tenant ID from the app registration into
auth_template.json
and rename it toauth.json
After completing the setup, run using python -m PhotoSorter
, then follow the instructions in the terminal. If you sort photos on OneDrive, you will need to sign in to your Microsoft Account.
Sometimes OneDrive doesn't "find" all of the photos that need to be sorted on the first pass, so the module may need to be ran multiple times if you find that only a small percentage of your photos have been moved. Even after running several times, some of your photos probably will not be moved because they are lacking the necessary metadata to determine when they were taken. If it has been some time since you last ran the module, you will need to delete token.txt
to reset the Microsoft account access.
Here's how to register an app on Microsoft Azure Active Directory (a.k.a. Microsoft Entra ID).
- Navigate to the Microsoft Azure Portal
- Click on
Microsoft Entra ID
underAzure Services
- Click on
App Registrations
in the left-hand sidebar underManage
- Click
New Registration
towards the top of the page - Fill out a name and select
Accounts in any organizational directory (Any Microsoft Entra ID tenant - Multitenant) and personal Microsoft accounts (e.g. Skype, Xbox)
, then clickRegister
- Copy the
Application (client) ID
andDirectory (tenant) ID
, you will need these to complete setup of the PhotoSorter - Click
Authentication
in the left-hand sidebar - Toggle
Allow public client flows
toYes
and Save
To set up for development, follow the same steps in the Installation section, except use pip install -e .
instead in step 5.
See LICENSE.md