added support for file extensions

This commit is contained in:
2025-10-05 19:43:09 +02:00
parent 9c39b773da
commit 8c81064743
2 changed files with 12 additions and 8 deletions

View File

@@ -22,6 +22,7 @@ class Refit_Create:
self.n = args.n
self.filemode = args.filemode
self.recursive = args.recursive
self.e = args.e
def create_n_folders(self, n, input, name):
"""Creates an set ammount of folders. Using the default directory
@@ -50,7 +51,7 @@ class Refit_Create:
os.mkdir(folder_creation_path)
n -= 1
def create_n_files(self, n, input, name):
def create_n_files(self, n, input, name, file_extension):
"""Creates an set ammount of files, using the default file name
if none is provided."""
@@ -71,7 +72,10 @@ class Refit_Create:
number_string = librefit.get_standard_name_number(file_number, length_n)
# Get the name of the file, either applying default or using first list item.
temp_name = f"{file_name}_{number_string}"
if file_extension is not None:
temp_name = f"{file_name}_{number_string}.{file_extension}"
else:
temp_name = f"{file_name}_{number_string}"
file_path = Path(os.path.join(input, temp_name)) # Build file path
file_path.touch(exist_ok=True) # creating file
@@ -127,19 +131,18 @@ class Refit_Create:
def create_dispatcher(self):
"""Coordination of the 'create' sub command"""
logger.debug("FUNC: create_dispatcher() MSG: Entered decider function")
logger.debug(
f"FUNC: create_dispatcher() MSG: Entered decider function {self.args}"
)
if self.input_validator():
if self.filemode:
logger.debug(
f"FUNC: create_dispatcher(filemode) MSG: given arguments: n={self.n} input={self.input} name={self.name}"
f"FUNC: create_dispatcher(filemode) MSG: given arguments: n={self.n} input={self.input} name={self.name} file_extension={self.e}"
)
self.create_n_files(self.n, self.input, self.name)
self.create_n_files(self.n, self.input, self.name, self.e)
elif self.recursive is not None:
# NOTE: for the dynamic name use two more args, if they
# exist, take them as name for the two dirs. else use
# default names
logger.debug(
f"FUNC: create_dispatcher(recursive) MSG: given arguments: n={self.n} input={self.input} name={self.name} recursive={self.recursive}"
)