poulet_py.tools.organizational module#
- check_or_create(path)[source]#
Function to check whether a folder exists. If it does NOT exist, it is created
- sanitize_path(path, *, add_timestamp=False)[source]#
Sanitize a full path by making all components filesystem-friendly and optionally adding a timestamp to the last component (file or folder).
- Parameters:
path (str) – The input path to sanitize (can include folders and filename)
add_timestamp (bool, optional) – If True, prepend timestamp in YYYYMMDD format to the last component
- Returns:
Sanitized path with all special characters replaced by underscores and optional timestamp on the last component
- Return type:
str
Examples
>>> sanitize_path("/s$ss!on1/d%ta/345.pkl", add_timestamp=True) '/s_ss_on1/d_ta/20250503_345.pkl'
>>> sanitize_path("my@project/data#files") 'my_project/data_files'
- go_to(key, *, path=None)[source]#
Change the current working directory to the level containing a specified key in a path.
- Parameters:
key (str) – The directory name to search for in the path (e.g., “neuropixels”).
path (Path or str, optional) – The input path to analyze. Defaults to the caller script’s location (__file__).
- Returns:
True if the directory was changed successfully, False otherwise.
- Return type:
bool
Examples
>>> change_dir_to_key("neuropixels", path="/project/neuropixels/src/file.py") True # Changes CWD to "/project/neuropixels"