Not only applicable to images, small modifications are enough to achieve new functions
This repository contains two Python scripts designed to manage photo files by organizing and restoring them within a directory structure. The scripts are photo_find_in_files.py for consolidating images and photo_back_to_files.py for restoring the original folder structure.
Python 3.x
This script searches through a specified source folder for image files (PNG, JPG, JPEG, GIF, BMP) and moves them to a designated destination folder. It also records the relative paths of the moved images in a text file for future reference.
- Supports multiple image formats.
- Creates the destination folder if it does not exist.
- Logs the relative path of each image in a record file.
src_folder = r"C:\Users\yuesen\Desktop\Source folder path" # Source folder path
dest_folder = r"C:\Users\yuesen\Desktop\Destination folder path" # Destination folder path
record_file = r"C:\Users\yuesen\Desktop\Record file path.txt" # Record file path
merge_images(src_folder, dest_folder, record_file)photo_back_to_files.py is a Python script designed to restore the original directory structure of photo files using a record file generated by the consolidation script. This script is particularly useful for organizing photos back into their original folders after they have been moved to a central location for backup or other purposes.
- Reads a record file to determine the original paths of the images.
- Creates necessary directories if they do not exist.
- Copies images from a central storage folder back to their respective original locations.
To use the script, you will need the path to the record file, the folder where the consolidated images are stored, and the output folder where the original directory structure should be restored.
record_file = r"C:\Users\yuesen\Desktop\Path to the record file.txt" # Path to the record file
images_folder = r"D:\edgedownload\Folder containing all images" # Folder containing all images
output_folder = r"C:\Users\yuesen\Desktop\Output folder path" # Output folder path
restore_folders(record_file, images_folder, output_folder)