python3.9的环境:
import os标签:__,删除,filepath,python,子目录,del,file,path,os From: https://blog.51cto.com/u_8681773/6004640
import sys
import shutil
from pathlib import Path
def del_file(filepath):
del_list = os.listdir(filepath)
for f in del_list:
file_path = os.path.join(filepath, f)
if os.path.isfile(file_path):
os.remove(file_path)
elif os.path.isdir(file_path):
shutil.rmtree(file_path)
os.rmdir(filepath)
#删除指定目录下的所有文件及其子目录
if __name__ == '__main__':
dir = Path(r'D:\datasets\gen_bigmoney_str\train')
#src = sys.argv[1]
del_file(dir)