Answers for "python remove file with pattern"

0

python remove file with pattern

import os
import glob

# Get a list of all the file paths that ends with .txt from in specified directory
file_list = glob.glob('/home/varung/Documents/python/logs/*.log')

# Iterate over the list of filepaths & remove each file.
for file_path in file_list:
    try:
        os.remove(file_path)
    except:
        print("Error while deleting file : ", file_path)
Posted by: Guest on May-14-2021

Code answers related to "python remove file with pattern"

Python Answers by Framework

Browse Popular Code Answers by Language