pyfvcom2.file_utils module

Tools to assist with file handling.

pyfvcom2.file_utils.find_file(dir_name: str, file_stem: str, date_time: datetime, tolerance_hours: int | None = 0) str[source]

Find a file in a directory matching a given stem and containing date_time within a given tolerance.

Args:

dir_name (str): Directory to search for files. file_stem (str): Stem of the file name to match. date_time (datetime): Datetime to match in the file name. tolerance_hours (int, optional): Tolerance in hours for datetime matching. Defaults to 1.

Returns:

str: Path to the matched file. int: Index of the time variable corresponding to the matched datetime.

Raises:

PyFVCOM2FileNotFoundError: If no matching file is found within the tolerance.

pyfvcom2.file_utils.find_files(dir_name: str, file_stem: str, start_date_time: datetime, end_date_time: datetime, tolerance_hours: int | None = 0) list[str][source]

Find all files in a directory matching a given stem and containing datetimes within a given range.

Args:

dir_name (str): Directory to search for files. file_stem (str): Stem of the file name to match. start_date_time (datetime): Start datetime to match in the file name. end_date_time (datetime): End datetime to match in the file name. tolerance_hours (int, optional): Tolerance in hours for datetime matching. Defaults to 1.

Returns:

list[str]: List of paths to the matched files.