Demo描述
创建一个空文件夹
代码实现
# 创建txt文件
# 创建 cam 文件夹 用来存放 共同目标的 图像检测结果
cam_path = r'../data_Python/cam'
if(os.path.exists(cam_path)):
shutil.rmtree(cam_path) # shutil.rmtree() 删除非空文件夹
os.mkdir(cam_path)
# 创建 lia 文件夹 用来存放 共同目标的 雷达检测结果
lia_path = r'../data_Python/lia'
if(os.path.exists(lia_path)):
shutil.rmtree(lia_path)
os.mkdir(lia_path)
# 创建 all_det 文件夹 用来存放 所有检测结果
all_det_path = r'../data_Python/all_det'
if(os.path.exists(all_det_path)):
shutil.rmtree(all_det_path)
os.mkdir(all_det_path)
# 创建 fus_det 文件夹 用来存放 融合检测结果
fus_det_path = r'../data_Python/fus_det'
if(os.path.exists(fus_det_path)):
shutil.rmtree(fus_det_path)
os.mkdir(fus_det_path)
# 创建 ellips_det 文件夹 用来存放 椭圆融合检测结果
ellips_det_path = r'../data_Python/ellips_det'
if(os.path.exists(ellips_det_path)):
shutil.rmtree(ellips_det_path)
os.mkdir(ellips_det_path)
代码改进
# 函数封装
def create_files(path):
if (os.path.exists(path)):
shutil.rmtree(path) # shutil.rmtree() 删除非空文件夹
os.mkdir(path)
# 创建 cam 文件夹 用来存放 共同目标的 图像检测结果
cam_path = r'../data_Python/cam'
create_files(cam_path)
# 创建 lia 文件夹 用来存放 共同目标的 雷达检测结果
lia_path = r'../data_Python/lia'
create_files(lia_path)
# 创建 all_det 文件夹 用来存放 所有检测结果
all_det_path = r'../data_Python/all_det'
create_files(all_det_path)
# 创建 fus_det 文件夹 用来存放 融合检测结果
fus_det_path = r'../data_Python/fus_det'
create_files(fus_det_path)
# 创建 ellips_det 文件夹 用来存放 椭圆融合检测结果
ellips_det_path = r'../data_Python/ellips_det'
create_files(ellips_det_path)