Create Folder
Create a folder recursively.
Create Folder
Processing
Creates a folder at the specified path recursively. Returns a status indicating success or failure and the absolute path of the created folder.
Inputs
- folder_path
- The path where the folder should be created.
Inputs Types
Input | Types |
---|---|
folder_path |
Str , DirectoryPath |
You can check the list of supported types here: Available Type Hints.
Outputs
- status
- A boolean indicating whether the folder creation was successful.
- full path
- The absolute path of the created or existing folder as a string.
Outputs Types
Output | Types |
---|---|
status |
Bool |
full path |
Str |
You can check the list of supported types here: Available Type Hints.
Options
The Create Folder brick contains some changeable options:
- Verbose
- Enables or disables logging of detailed information about the folder creation process, such as success messages or error details. Defaults to True.
import logging
from coded_flows.types import Str, Path, DirectoryPath, Tuple, Union, Bool
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)
def create_folder(
folder_path: Union[Str, DirectoryPath], options=None
) -> Tuple[Bool, Str]:
brick_display_name = "Create Folder"
options = options or {}
verbose = options.get("verbose", True)
status = True
full_path = ""
try:
path_obj = Path(folder_path)
absolute_path = path_obj.resolve()
if absolute_path.exists():
if absolute_path.is_dir():
verbose and logger.info(
f"[{brick_display_name}] Folder already exists: '{absolute_path}'."
)
full_path = str(absolute_path)
else:
verbose and logger.error(
f"[{brick_display_name}] Path exists but is not a directory: '{absolute_path}'"
)
status = False
absolute_path.mkdir(parents=True, exist_ok=True)
verbose and logger.info(
f"[{brick_display_name}] Successfully created folder: '{absolute_path}'."
)
full_path = str(absolute_path)
except PermissionError as e:
verbose and logger.error(
f"[{brick_display_name}] Permission denied when creating folder '{folder_path}': {e}"
)
status = False
except OSError as e:
verbose and logger.error(
f"[{brick_display_name}] OS error when creating folder '{folder_path}': {e}"
)
status = False
except Exception as e:
verbose and logger.error(
f"[{brick_display_name}] Unexpected error when creating folder '{folder_path}': {e}"
)
status = False
return (status, full_path)
Brick Info
version
v0.1.4
python
3.10,
3.11,
3.12,
3.13
requirements
-
-