-
Notifications
You must be signed in to change notification settings - Fork 1
/
CreateRunTimestampDirectory_old.py
59 lines (45 loc) · 1.96 KB
/
CreateRunTimestampDirectory_old.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#Script name: CreateRunTimestampDirectory.py
import os
import datetime
import shutil
import configparser
def create_run_directory():
# Read the video path from the ini file
config = configparser.ConfigParser()
config.read("config.ini")
image_path = config["Settings"]["image_path"]
# Create the output directory
output_directory = os.path.splitext(image_path)[0] + "_out"
# if not os.path.exists(output_directory):
# os.makedirs(output_directory)
#
# # Print a message to confirm that the folder was created
# print(f"Created output directory: {output_directory}")
# # Create the output directory
# output_directory = os.path.splitext(video_path)[0] + "_out"
# Get the current time and date
now = datetime.datetime.now()
# Format the time and date into a string
timestamp = now.strftime("%Y-%m-%d_%H-%M-%S")
# Create the run_timestamp directory
run_directory: str = os.path.join(output_directory, timestamp)
# Add the output directory line to the config file
config["Settings"]["output_directory"] = run_directory
config["Settings"]["output_dir_Message"] = "output_directory is auto-generated."
# Write the updated config file
with open("config.ini", "w") as configfile:
config.write(configfile)
if not os.path.exists(run_directory):
os.makedirs(run_directory)
# Copy the config.ini file to the run directory
config_file = os.path.join("config.ini")
if os.path.exists(config_file):
shutil.copy(config_file, os.path.join(run_directory, "previous_config.ini"))
# Create output directories for related output folders
# output_directories = ["output", "images", "logs"]
# for output_directory in output_directories:
# output_path = os.path.join(run_directory, output_directory)
# if not os.path.exists(output_path):
# os.makedirs(output_path)
# Call the function to create a run directory
create_run_directory()