rogerxavier commited on
Commit
8cea993
1 Parent(s): 6bd6492

Update api.py

Browse files
Files changed (1) hide show
  1. api.py +11 -4
api.py CHANGED
@@ -56,11 +56,18 @@ def getOriginalMangaList(images: List[UploadFile] = File(...), save_path: str =
56
 
57
  ##这个比较快不用异步
58
  @app.delete("/deleteFiles")
59
- async def delete_files(directory: str):
60
- for filename in os.listdir(directory):
61
- file_path = os.path.join(directory, filename)
62
- if os.path.isfile(file_path):
 
63
  os.remove(file_path)
 
 
 
 
 
 
64
  return {"message": f"成功删除{directory}目录下的所有文件"}
65
  ##这个比较快不用异步
66
 
 
56
 
57
  ##这个比较快不用异步
58
  @app.delete("/deleteFiles")
59
+ async def delete_all_files_and_folders(directory:str):
60
+ for root, dirs, files in os.walk(directory, topdown=False):
61
+ for name in files:
62
+ file_path = os.path.join(root, name)
63
+ print("删除指定目录函数检查到文件,删除文件:", file_path)
64
  os.remove(file_path)
65
+ for name in dirs:
66
+ dir_path = os.path.join(root, name)
67
+ print("删除指定目录函数检查到目录,删除目录:", dir_path)
68
+ os.rmdir(dir_path)
69
+ # 删除根目录
70
+ os.rmdir(directory)
71
  return {"message": f"成功删除{directory}目录下的所有文件"}
72
  ##这个比较快不用异步
73