Created
July 8, 2024 17:50
-
-
Save estevaofon/83db805a47bbf890c710cf44a740c011 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import shutil | |
from PIL import Image | |
def is_image(file_path): | |
try: | |
with Image.open(file_path) as img: | |
return True | |
except (IOError, FileNotFoundError): | |
return False | |
def gather_photos(source_folder, destination_folder='photos_gathered'): | |
if not os.path.exists(destination_folder): | |
os.makedirs(destination_folder) | |
for root, _, files in os.walk(source_folder): | |
for file in files: | |
file_path = os.path.join(root, file) | |
if is_image(file_path): | |
shutil.copy(file_path, destination_folder) | |
print(f"Copied: {file_path}") | |
if __name__ == "__main__": | |
source_folder = r"C:\Users\estev\Pictures" # You can change this to any directory you want to scan | |
gather_photos(source_folder) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment