The Palos Publishing Company

Follow Us On The X Platform @PalosPublishing
Categories We Write About

Image File Organizer Script

Here is a Python script for organizing image files into folders based on their file type or creation date. You can choose your preferred organization method by changing the mode variable.

python
import os import shutil from datetime import datetime # Configuration source_folder = '/path/to/your/images' # Change this to your image directory destination_root = '/path/to/organized/images' # Where to organize the files mode = 'date' # Options: 'date' or 'type' # Supported image formats image_extensions = {'.jpg', '.jpeg', '.png', '.gif', '.bmp', '.tiff', '.webp'} def get_file_creation_date(path): # Use last modified date as fallback timestamp = os.path.getmtime(path) return datetime.fromtimestamp(timestamp).strftime('%Y-%m-%d') def organize_by_date(): for filename in os.listdir(source_folder): if not any(filename.lower().endswith(ext) for ext in image_extensions): continue file_path = os.path.join(source_folder, filename) date_folder = get_file_creation_date(file_path) target_folder = os.path.join(destination_root, date_folder) os.makedirs(target_folder, exist_ok=True) shutil.move(file_path, os.path.join(target_folder, filename)) print(f"Moved {filename} to {target_folder}") def organize_by_type(): for filename in os.listdir(source_folder): ext = os.path.splitext(filename)[1].lower() if ext not in image_extensions: continue target_folder = os.path.join(destination_root, ext[1:]) # remove dot from extension os.makedirs(target_folder, exist_ok=True) shutil.move(os.path.join(source_folder, filename), os.path.join(target_folder, filename)) print(f"Moved {filename} to {target_folder}") if __name__ == "__main__": if not os.path.exists(source_folder): print(f"Source folder does not exist: {source_folder}") elif mode == 'date': organize_by_date() elif mode == 'type': organize_by_type() else: print("Invalid mode. Use 'date' or 'type'.")

How to Use:

  1. Replace /path/to/your/images with the folder containing your images.

  2. Replace /path/to/organized/images with the folder where you want to organize images.

  3. Set mode to 'date' to sort into folders by creation date (e.g., 2025-05-18), or 'type' to sort by file type (e.g., jpg, png).

  4. Run the script.

Let me know if you’d like to add features like duplicate checking, file renaming, or EXIF-based sorting.

Share this Page your favorite way: Click any app below to share.

Enter your email below to join The Palos Publishing Company Email List

We respect your email privacy

Categories We Write About