📚 Introduction
Managing image files from Excel lists manually is tedious. In this tutorial, we’ll automate it using Python: read Excel files, extract image names, and copy them into organized folders with logging support.
🛠 Requirements
- Python installed: Download here
- Install libraries:
pip install pandas openpyxl
📁 Folder Structure
📂 SBL Homeopathy/
├── All Product Images/
│ └── photo1.jpg, photo2.png
├── Excel Image Lists/
│ └── images 1.xlsx, images 2.xlsx, ...
└── Sorted Images/ (created by script)
🐍 Python Script
import os
import shutil
import pandas as pd
# CONFIG
excel_folder = r'C:\\Path\\To\\Excel Image Lists'
source_folder = r'C:\\Path\\To\\All Product Images'
output_base = r'C:\\Path\\To\\Sorted Images'
image_column = 'ImageName'
allowed_extensions = {{'.jpg', '.jpeg', '.png'}}
copy_files = True
os.makedirs(output_base, exist_ok=True)
excel_files = [f for f in os.listdir(excel_folder) if f.endswith('.xlsx')]
log_missing, log_copied = [], []
total_copied = 0
for file in excel_files:
file_path = os.path.join(excel_folder, file)
folder_name = os.path.splitext(file)[0]
dest_folder = os.path.join(output_base, folder_name)
os.makedirs(dest_folder, exist_ok=True)
print(f"📄 Processing: {{file}}")
try:
df = pd.read_excel(file_path)
except Exception as e:
print(f"❌ Could not read {{file}}: {{e}}")
continue
if image_column not in df.columns:
print(f"⚠️ Missing column '{{image_column}}' in {{file}}")
continue
image_list = df[image_column].dropna().astype(str).tolist()
copied_count = 0
for image in image_list:
image = image.strip()
ext = os.path.splitext(image)[1].lower()
if ext not in allowed_extensions:
continue
src = os.path.join(source_folder, image)
dest = os.path.join(dest_folder, image)
if os.path.exists(src):
shutil.copy2(src, dest) if copy_files else shutil.move(src, dest)
copied_count += 1
log_copied.append(f"{{image}} -> {{folder_name}}")
else:
log_missing.append(f"{{image}} (from {{folder_name}})")
print(f"✅ Copied {{copied_count}} files to: {{dest_folder}}")
total_copied += copied_count
with open(os.path.join(output_base, 'copied_files.txt'), 'w') as f:
f.write('\\n'.join(log_copied))
with open(os.path.join(output_base, 'missing_files.txt'), 'w') as f:
f.write('\\n'.join(log_missing))
print(f"🎉 Total images copied: {{total_copied}}")
✅ Output Structure
📂 Sorted Images/
├── images 1/
├── images 2/
└── images 3/
📌 Tips
- Make sure Excel names match image files exactly.
- Use only supported formats (.jpg, .jpeg, .png)
- Delete empty Excel rows before running.
🧠 Why Use This?
- 🚀 Fast image organization
- 🧠 Eliminates manual errors
- 🔁 Reusable with different Excel sheets
📦 Logs Created
copied_files.txt – files successfully copied missing_files.txt – image names not found in source
🔖 Tags & SEO Keywords
Keywords: python sort images from excel, copy images from excel list, excel to folder automation, organize product images, image management script, python pandas shutil excel automation, python for ecommerce inventory, how to use shutil and pandas to sort images, folder sort by excel file, product image workflow, blogger compatible html post
Tags: Python Automation Excel to Folder Image Sorting Product Catalog Management Python for Beginners eCommerce Tools Inventory Workflow
🔚 Conclusion
This script is essential for bulk image sorting, especially for product managers, catalog designers, and eCommerce teams. Automate it once and save hours every month!