Python Script: « Video and Photo Sorter »
This script organizes your files by separating videos and photos into two distinct folders.
python
Copier le codeimport os import shutil def sort_photos_and_videos(source_dir, photo_dir, video_dir): """ Organizes files by separating photos and videos into distinct folders. :param source_dir: Path to the source folder containing the files. :param photo_dir: Path to the folder where photos will be moved. :param video_dir: Path to the folder where videos will be moved. """ # Create destination folders if they don't exist if not os.path.exists(photo_dir): os.makedirs(photo_dir) if not os.path.exists(video_dir): os.makedirs(video_dir) # Photo and video file extensions photo_extensions = [".jpg", ".jpeg", ".png", ".gif", ".bmp"] video_extensions = [".mp4", ".mov", ".avi", ".mkv", ".wmv", ".flv"] for root, dirs, files in os.walk(source_dir): for file in files: source_path = os.path.join(root, file) # Check if it's a photo if file.lower().endswith(tuple(photo_extensions)): destination_path = os.path.join(photo_dir, file) # Check if it's a video elif file.lower().endswith(tuple(video_extensions)): destination_path = os.path.join(video_dir, file) else: # Skip files that do not match continue # Handle file name conflicts if os.path.exists(destination_path): base, ext = os.path.splitext(file) count = 1 while os.path.exists(destination_path): destination_path = os.path.join( os.path.dirname(destination_path), f"{base}_{count}{ext}" ) count += 1 # Move the file shutil.move(source_path, destination_path) print(f"Moved: {source_path} -> {destination_path}") # Source folder path source_dir = r"C:\Users\info\OneDrive\famille photo" # Destination folders for photos and videos photo_dir = r"C:\Users\info\OneDrive\famille photo\photos" video_dir = r"C:\Users\info\OneDrive\famille photo\videos" # Call the function sort_photos_and_videos(source_dir, photo_dir, video_dir)
How to Use the « Video and Photo Sorter »
Modify the paths in the script:source_dir
: The folder containing all your files.photo_dir
: The folder for photos.video_dir
: The folder for videos.
Run the script:
Save the script to a .py
file (e.g., video_photo_sorter.py
).
Run it from a terminal:bash
Copier le codepython video_photo_sorter.py
Result:
All photos will be moved to the photos
folder.
All videos will be moved to the videos
folder.
Files of other types will remain untouched.
Presentation for the BioZnum Website
Video and Photo Sorter – A BioZnum Tool
The Video and Photo Sorter is a simple and practical tool for automatically organizing your multimedia files by separating photos and videos into distinct folders.
Key Features:
Automatic detection of photos (.jpg
, .png
, etc.) and videos (.mp4
, .avi
, etc.).
Automatically creates photos
and videos
folders if they don’t exist.
Intelligent file name conflict handling with automatic renaming.
Perfect for quickly organizing your multimedia files.
Why Use It?
Save hours of manually sorting your files.
Align with BioZnum’s mission to simplify and improve digital management.
This tool is free, open-source, and a perfect addition to any digital workflow! 🚀😊
Let me know if you’d like further refinements or a simplified version!
4o