📜  python 删除带有模式的文件 - Python 代码示例

📅  最后修改于: 2022-03-11 14:46:07.177000             🧑  作者: Mango

代码示例1
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)