JasonXF's picture
Add files using upload-large-folder tool
787163a verified
Raw
History Blame Contribute Delete
642 Bytes
import os
from pathlib import Path
def delete_files(folder_path, file_name):
# 使用Path对象遍历文件夹内所有文件
for filepath in Path(folder_path).rglob(file_name):
try:
os.remove(filepath) # 尝试删除文件
print(f"Deleted: {filepath}")
except OSError as e:
print(f"Error: {filepath} : {e.strerror}")
# 指定顶层目录,将递归搜索此目录及其所有子目录
top_level_folder = os.getcwd()
# 指定要删除的文件名
file_to_delete = 'deleteResults.bat'
# 调用函数进行删除
delete_files(top_level_folder, file_to_delete)