Caporlingua Marina
update docstrings
bc3dd01
raw
history blame
1.58 kB
import os
from typing import List
def create_project_structure(base_path: str, folders: List[str]) -> None:
"""
Creates a folder structure within the specified base path if it doesn't already exist.
This function iterates over a list of folder paths and creates the corresponding directories
within the specified base path. If a folder already exists, it skips creation without errors.
Args:
base_path (str): The base directory where the folders will be created.
folders (List[str]): A list of folder paths (relative to `base_path`) to be created.
Returns:
None: This function does not return a value.
Raises:
OSError: If there is an issue creating any of the directories, an error message is printed.
Example:
create_project_structure("/home/user/project", ["data", "logs", "output"])
This will create the following structure if it doesn't already exist:
/home/user/project/data
/home/user/project/logs
/home/user/project/output
"""
for folder in folders:
folder_path = os.path.join(base_path, folder)
try:
os.makedirs(folder_path, exist_ok=True)
print(f"Folder '{folder_path}' created successfully.")
except Exception as e:
print(f"An error occurred while creating the folder '{folder_path}': {e}")
# Example usage
base_path = "."
folders = [
"data/",
"data/eurostat/",
"data/istat/",
"modules/",
"schemas/",
"test"
]
create_project_structure(base_path, folders)