增加删除推理集合接口
This commit is contained in:
@ -89,3 +89,24 @@ def delete_file_if_exists(*file_paths: str):
|
||||
for path in file_paths:
|
||||
if os.path.exists(path): # 检查文件是否存在
|
||||
os.remove(path) # 删除文件
|
||||
|
||||
|
||||
def delete_paths(paths):
|
||||
"""
|
||||
删除给定路径数组中的每个路径及其包含的所有内容。
|
||||
:param paths: 文件或目录路径的列表
|
||||
"""
|
||||
for path in paths:
|
||||
if os.path.exists(path):
|
||||
try:
|
||||
if os.path.isfile(path) or os.path.islink(path):
|
||||
# 如果是文件或符号链接,则删除
|
||||
os.remove(path)
|
||||
print(f"Deleted file: {path}")
|
||||
elif os.path.isdir(path):
|
||||
# 如果是目录,则递归删除
|
||||
shutil.rmtree(path)
|
||||
except Exception as e:
|
||||
print(f"路径删除失败 {path}: {e}")
|
||||
else:
|
||||
print(f"路径不存在: {path}")
|
||||
|
Reference in New Issue
Block a user