find_files(names: Union[list, str], root_paths: Union[list, str, CloudPath, Path], max_nof_files: int = -1, get_as_str: bool = False) Union[list, str][source]#

Returns matching files recursively from a list of root paths.

Regex are allowed (using glob)

>>> root_path = 'D:/root'
>>> dir1_path = 'D:/root/dir1'
>>> dir2_path = 'D:/root/dir2'

>>> os.listdir(dir1_path)
["haha.txt", "huhu.txt", "hoho.txt"]
>>> os.listdir(dir2_path)
["huhu.txt", "hehe.txt"]

>>> find_files("huhu.txt", root_path)
['D:/root/dir1/huhu.txt', 'D:/root/dir2/huhu.txt']

>>> find_files("huhu.txt", root_path, max_nof_files=1)

>>> find_files("huhu.txt", root_path, max_nof_files=1, get_as_str=True)
found = 'D:/root/dir1/huhu.txt'
  • names (Union[list, str]) – File names.

  • root_paths (Union[list, str]) – Root paths

  • max_nof_files (int) – Maximum number of files (set to -1 for unlimited)

  • get_as_str (bool) – if only one file is found, it can be retrieved as a string instead of a list


File name

Return type: