1import os
2import glob
3
4# Get a list of all the file paths that ends with .txt from in specified directory
5file_list = glob.glob('/home/varung/Documents/python/logs/*.log')
6
7# Iterate over the list of filepaths & remove each file.
8for file_path in file_list:
9 try:
10 os.remove(file_path)
11 except:
12 print("Error while deleting file : ", file_path)