Create a Photo Organiser with Python by ChatGPT

GeoSense ✅
2 min readFeb 11, 2023

I like my photos organised into folders according to the month they were shot so that I can easily go back and view them or search for them. So I want this to be done automatically, with Python. Problem is defined! Let’s get started!

The full code is here:

import os
import shutil
import datetime

# path to the source directory
src_dir = 'photos'

# path to the destination directory for photos
photo_dest_dir = 'PT'

# path to the destination directory for videos
video_dest_dir = 'VD'

# list of file extensions for photos
photo_extensions = ['.jpg', '.jpeg', '.png', '.bmp','.heic']

# list of file extensions for videos
video_extensions = ['.mp4', '.avi', '.mkv', '.mov']

# iterate over all files in the source directory
for filename in os.listdir(src_dir):
# get the file creation time
file_ctime = os.path.getctime(os.path.join(src_dir, filename))
# convert the creation time to a datetime object
file_ctime = datetime.datetime.fromtimestamp(file_ctime)
# get the file extension
file_extension = os.path.splitext(filename)[1].lower()

# check if the file is a photo
if file_extension in photo_extensions:
# create the destination directory for the photo based on its creation date
dest_dir = os.path.join(photo_dest_dir, str(file_ctime.year), str(file_ctime.month))
# create the destination…

--

--

GeoSense ✅

🌏 Remote sensing | 🛰️ Geographic Information Systems (GIS) | ℹ️ https://www.tnmthai.com/medium