Created
December 11, 2020 13:22
-
-
Save gayu19/b98db44ecfc5e880ba4650472e292e84 to your computer and use it in GitHub Desktop.
Deletes the file with particular extension
This file contains 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
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