Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

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)
Source by thispointer.com #
 
PREVIOUS NEXT
Tagged: #python #remove #file #pattern
ADD COMMENT
Topic
Name
9+6 =