Skip to content

Instantly share code, notes, and snippets.

@Eveeifyeve
Created February 10, 2024 09:37
Show Gist options
  • Save Eveeifyeve/03158ea58a0369684c2c2266504f96a9 to your computer and use it in GitHub Desktop.
Save Eveeifyeve/03158ea58a0369684c2c2266504f96a9 to your computer and use it in GitHub Desktop.
deleteShotsPyScrpt
import os
# Set the target directory
target_directory = os.path.expanduser('~/documents/screenshots')
# Loop through all files in the target directory
for filename in os.listdir(target_directory):
# Check if the file ends with the extensions we want to delete
if filename.endswith('.png') or filename.endswith('.jpg') or filename.endswith('.jpeg'):
# Construct full file path
file_path = os.path.join(target_directory, filename)
# Remove the file
try:
os.remove(file_path)
print(f"Removed {filename}")
except OSError as e:
print(f"Error: {e.strerror}")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment