Skip to content

Instantly share code, notes, and snippets.

@JEuler
Created March 4, 2024 13:49
Show Gist options
  • Save JEuler/6a5836da17e48148c10226b565c3725a to your computer and use it in GitHub Desktop.
Save JEuler/6a5836da17e48148c10226b565c3725a to your computer and use it in GitHub Desktop.
Extract .jpg files from folders in some current folder.
import os
import shutil
def extract_jpg_files(root_folder):
for root, dirs, files in os.walk(root_folder):
for file in files:
if file.endswith('.jpg'):
source_path = os.path.join(root, file)
destination_path = os.path.join(root_folder, file)
shutil.move(source_path, destination_path)
print(f'Moved: {source_path} -> {destination_path}')
# Use the current working directory as the root folder
root_folder_path = os.getcwd()
extract_jpg_files(root_folder_path)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment