Python
파이썬 폴더 없으면 생성하기, 코드 시작 시간으로 폴더 생성하기 os.path.exists(), time.localtime()
koos808
2021. 4. 11. 21:59
728x90
반응형
# 폴더 없으면 생성하기
1. 기본 코드
import os
if not os.path.exists(model_object_file_path):
os.makedirs(model_object_file_path)
2. 응용 : 추가로 weight와 output path 시간단위로 폴더만들어서 저장하기
# weight, output images path 설정 및 folder 생성
import os
import time
output_save_folder_path = os.getcwd() + '/detect_output/'
output_path = os.path.join(output_save_folder_path, time.strftime('%Y%m%d_%H_%M', time.localtime(time.time())))
weight_save_folder_path = os.getcwd() + '/detect_weights/'
weight_path = os.path.join(weight_save_folder_path, time.strftime('%Y%m%d_%H_%M', time.localtime(time.time())))
if not os.path.exists(output_save_folder_path):
os.mkdir(output_save_folder_path)
if not os.path.exists(output_path):
os.mkdir(output_path)
if not os.path.exists(weight_save_folder_path):
os.mkdir(weight_save_folder_path)
if not os.path.exists(weight_path):
os.mkdir(weight_path)
728x90
반응형