fixed numbering in recursion

This commit is contained in:
2025-10-04 12:16:59 +02:00
parent 9d2d6931e3
commit 8df12ec6f4
3 changed files with 16 additions and 12 deletions

View File

@@ -24,14 +24,14 @@ def get_standard_name_number(current_number: int, number_str_length: int) -> str
>>> get_standard_name_number(23, 4)
'0023'
"""
# logger.debug(
# f"FUNC: get_standard_name_number() index={current_number} string_length={number_str_length}"
# )
logger.debug(
f"FUNC: get_standard_name_number() index={current_number} string_length={number_str_length}"
)
temp_current_number = str(current_number)
standard_name_number = str.zfill(temp_current_number, number_str_length)
# logger.debug(
# f"FUNC: get_standard_name_number() return value= '{standard_name_number}'"
# )
logger.debug(
f"FUNC: get_standard_name_number() return value= '{standard_name_number}'"
)
return standard_name_number
@@ -151,20 +151,25 @@ def get_current_path(path) -> str:
def create_recursive_folders(input_path, target_depth, current_depth, width):
"""Creates a recursive directory structure with y as depth and x as width"""
# Exits the recursion if the target depth is reached.
if current_depth >= target_depth:
return
# Getting the lenth of the number string which gets added to the dir name.
length_width = len(str(width))
logger.debug(
f"FUNC: create_recursive_folders(length_width) MSG: length_width='{length_width}'"
f"FUNC: create_recursive_folders(length_width) MSG: given values: path={input_path} target_depth={target_depth} current_depth={current_depth}, with={width}"
)
# Creates the directories of the current depth
for i in range(width):
# Getting the numbering of the folder.
folder_index = i + 1
new_directory_name = "sub_dir" + get_standard_name_number(
length_width, folder_index
folder_index, length_width
)
new_directory_path = os.path.join(input_path, new_directory_name)
os.mkdir(new_directory_path)
print(new_directory_path)
logger.debug(f"New Path: path={new_directory_path}")
@@ -174,6 +179,3 @@ def create_recursive_folders(input_path, target_depth, current_depth, width):
current_depth + 1,
width,
)
# create_recursive_folders(".", 2, 0, 3)