Find files recursively. Args: root_dir (str): Root root_dir to find. query (str): Query to find. include_root_dir (bool): If False, root_dir name is not included. Returns: list: List of found filenames.
(root_dir, query="*.wav", include_root_dir=True)
| 20 | |
| 21 | |
| 22 | def find_files(root_dir, query="*.wav", include_root_dir=True): |
| 23 | """Find files recursively. |
| 24 | Args: |
| 25 | root_dir (str): Root root_dir to find. |
| 26 | query (str): Query to find. |
| 27 | include_root_dir (bool): If False, root_dir name is not included. |
| 28 | Returns: |
| 29 | list: List of found filenames. |
| 30 | """ |
| 31 | files = [] |
| 32 | for root, _, filenames in os.walk(root_dir, followlinks=True): |
| 33 | for filename in fnmatch.filter(filenames, query): |
| 34 | files.append(os.path.join(root, filename)) |
| 35 | if not include_root_dir: |
| 36 | files = [file_.replace(root_dir + "/", "") for file_ in files] |
| 37 | |
| 38 | return files |
| 39 | |
| 40 | |
| 41 | def _path_requires_gfile(filepath): |