check_files_exist

pyhelpers.dirs.check_files_exist(filenames, path_to_dir)[source]

Check if specified files exist within a given directory.

Parameters:
  • filenames (Iterable) – Filenames to check for existence.

  • path_to_dir (str | os.PathLike) – Path to the directory where files are to be checked.

Returns:

True if all queried files exist in the directory, False otherwise.

Return type:

bool

Examples:

>>> from pyhelpers.dirs import check_files_exist
>>> test_dir_name = "tests/data"
>>> # Check if all required files exist in the directory
>>> check_files_exist(["dat.csv", "dat.txt"], test_dir_name)
True
>>> # If not all required files exist, print the missing files
>>> check_files_exist(("dat.csv", "dat.txt", "dat_0.txt"), test_dir_name)
Error: Required files are not satisfied, missing files are: ['dat_0.txt']
False