check_file_path#
- caf.van.utilities.check_file_path(path, name, *extensions, return_path=False)[source]#
Check that the given path is an existing file.
Also checks if the file contains the correct file extension, if any are given.
- Parameters:
path (Path) – Path to be checked.
name (str) – Name used for error messages.
*extensions (str, optional) – Any number of extension strings to check e.g. “.csv”, “.txt”
return_path (bool, default False) – If True returns the Path, otherwise returns boolean for if the file exists and has the correct extension.
- Returns:
If return_path then returns the path (as a Path object), otherwise returns True if the file exists and has the correct extension.
- Return type:
bool or Path
- Raises:
FileNotFoundError – If the file doesn’t exist, is a folder or isn’t the correct extension.