Skip to content

Instantly share code, notes, and snippets.

@gayu19
Created December 11, 2020 13:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gayu19/b98db44ecfc5e880ba4650472e292e84 to your computer and use it in GitHub Desktop.
Save gayu19/b98db44ecfc5e880ba4650472e292e84 to your computer and use it in GitHub Desktop.
Deletes the file with particular extension
from os import listdir, remove
from os.path import isfile, join, splitext
from datetime import datetime
print(datetime.now().strftime("%H:%M:%S"))
def delete_files():
"""Deletes the file from given path with given extension
"""
mypath = '/users/gayatrikale/Downloads/'
for f in listdir(mypath):
filename, ext = splitext(f)
if isfile(join(mypath, f)) and ext=='.png':
remove(join(mypath, f))
print(f'removed {filename}')
else:
print('.png file does not exist')
delete_files()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment