Skip to content

File Handler

This module contains functions to handle files and folders.

ATTRIBUTE DESCRIPTION
TEMP_ZIP

temporary zip file path

TYPE: Path

FUNCTION DESCRIPTION
create_folder

Check and create folder if it does not exist

init

Add repository to sys.path, and get machine id and connected ports

read_config_file

Read configuration file and return as dictionary

readable_duration

Display time duration (s) as HH:MM:SS text

resolve_repo_filepath

Resolve relative path to absolute path

start_project_here

Create new project in destination directory

zip_files

Zip files and return zip file path

Documentation last updated: 2025-06-11

create_folder

create_folder(
    base: Path | str = "", sub: Path | str = ""
) -> Path

Check and create folder if it does not exist

PARAMETER DESCRIPTION
base

parent folder directory. Defaults to ''.

TYPE: Path | str DEFAULT: ''

sub

child folder directory. Defaults to ''.

TYPE: Path | str DEFAULT: ''

RETURNS DESCRIPTION
Path

name of main folder

TYPE: Path

init

init(repository: str | Path) -> str

Add repository to sys.path, and getting machine id and connected ports

PARAMETER DESCRIPTION
repository

name of current repository, or path to repository folder

TYPE: str | Path

RETURNS DESCRIPTION
str

target directory path

TYPE: str

read_config_file

read_config_file(filepath: Path | str) -> dict

Read configuration file and return as dictionary

PARAMETER DESCRIPTION
filepath

path to configuration file

TYPE: Path | str

RETURNS DESCRIPTION
dict

configuration file as dictionary

TYPE: dict

RAISES DESCRIPTION
ValueError

Unsupported file type

readable_duration

readable_duration(total_time: float) -> str

Display time duration (s) as HH:MM:SS text

PARAMETER DESCRIPTION
total_time

duration in seconds

TYPE: float

RETURNS DESCRIPTION
str

formatted time string

TYPE: str

resolve_repo_filepath

resolve_repo_filepath(filepath: Path | str) -> Path

Resolve relative path to absolute path

PARAMETER DESCRIPTION
filepath

relative path to file

TYPE: Path | str

RETURNS DESCRIPTION
Path

absolute path to file

TYPE: Path

start_project_here

start_project_here(dst: Path | str | None = None)

Create new project in destination directory. If destination is not provided, create in current directory

PARAMETER DESCRIPTION
dst

destination folder. Defaults to None.

TYPE: Path | str | None DEFAULT: None

zip_files

zip_files(
    filepaths: Iterable[Path],
    zip_filepath: str | Path | None = None,
) -> Path

Zip files and return zip file path

PARAMETER DESCRIPTION
filepaths

list of file paths

TYPE: Iterable[Path]

zip_filepath

zip file path. Defaults to None.

TYPE: str | Path | None DEFAULT: None

RETURNS DESCRIPTION
Path

zip file path

TYPE: Path