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

@@ -25,6 +25,8 @@ n -> valid input check back for no arguments passed?
## Changelog ## Changelog
<2025-10-04> V0.3.4 - Added recursive directory creation and fixed
numbered naming
<2025-10-03> V0.3.3 - Added the beginning of recursive mode <2025-10-03> V0.3.3 - Added the beginning of recursive mode
<2025-09-30> V0.3.2 - Refactoring librefit and added proper docstrings; <2025-09-30> V0.3.2 - Refactoring librefit and added proper docstrings;
begun to remove the check for the valid input and put it in the decider begun to remove the check for the valid input and put it in the decider

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) >>> get_standard_name_number(23, 4)
'0023' '0023'
""" """
# logger.debug( logger.debug(
# f"FUNC: get_standard_name_number() index={current_number} string_length={number_str_length}" f"FUNC: get_standard_name_number() index={current_number} string_length={number_str_length}"
# ) )
temp_current_number = str(current_number) temp_current_number = str(current_number)
standard_name_number = str.zfill(temp_current_number, number_str_length) standard_name_number = str.zfill(temp_current_number, number_str_length)
# logger.debug( logger.debug(
# f"FUNC: get_standard_name_number() return value= '{standard_name_number}'" f"FUNC: get_standard_name_number() return value= '{standard_name_number}'"
# ) )
return 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): def create_recursive_folders(input_path, target_depth, current_depth, width):
"""Creates a recursive directory structure with y as depth and x as 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: if current_depth >= target_depth:
return return
# Getting the lenth of the number string which gets added to the dir name.
length_width = len(str(width)) length_width = len(str(width))
logger.debug( 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): for i in range(width):
# Getting the numbering of the folder.
folder_index = i + 1 folder_index = i + 1
new_directory_name = "sub_dir" + get_standard_name_number( 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) new_directory_path = os.path.join(input_path, new_directory_name)
os.mkdir(new_directory_path)
print(new_directory_path) print(new_directory_path)
logger.debug(f"New Path: path={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, current_depth + 1,
width, width,
) )
# create_recursive_folders(".", 2, 0, 3)

View File

@@ -1,5 +1,5 @@
[VERSION] [VERSION]
major = 0 major = 0
minor = 3 minor = 3
patch = 3 patch = 4