parse_date_from_path

bidsaid.path_utils.parse_date_from_path(path, date_fmt)[source]

Get date from the stem of a path.

Parameters

pathstr or Path

The absolute path, name of file, or folder.

date_fmtstr

The expected format of the date.

Returns

str or None

A string if a valid date based on specified date_fmt is detected or None if no valid date is detected.

Example

>>> from bidsaid.path_utils import parse_date_from_path
>>> date_str = parse_date_from_path("101_240820_mprage_32chan.nii", "%y%m%d")
>>> print(date_str)
    "240820"
>>> folder = r"Users/users/Documents/101_240820"
>>> date_str = parse_date_from_path(folder, "%y%m%d")
>>> print(date_str)
    "240820"