check_files_exist

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

Check if queried files exist in a given directory.

Parameters:
  • filenames (list) – a list of filenames

  • path_to_dir (str | os.PathLike) – a list of filenames in the directory

Returns:

True if all the queried files exist, 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