Recursively match files in a directory according to a pattern. Parameters ---------- stem : str The directory in which to recurse file_pattern : str The filename regex pattern to which to match. Returns ------- matches_list : list A list of
(stem, file_pattern)
| 1831 | |
| 1832 | |
| 1833 | def recursive_glob(stem, file_pattern): |
| 1834 | """ |
| 1835 | Recursively match files in a directory according to a pattern. |
| 1836 | |
| 1837 | Parameters |
| 1838 | ---------- |
| 1839 | stem : str |
| 1840 | The directory in which to recurse |
| 1841 | file_pattern : str |
| 1842 | The filename regex pattern to which to match. |
| 1843 | |
| 1844 | Returns |
| 1845 | ------- |
| 1846 | matches_list : list |
| 1847 | A list of filenames in the directory that match the file pattern. |
| 1848 | """ |
| 1849 | |
| 1850 | if sys.version_info >= (3, 5): |
| 1851 | return glob(stem + "/**/" + file_pattern, recursive=True) |
| 1852 | else: |
| 1853 | # gh-316: this will avoid invalid unicode comparisons in Python 2.x |
| 1854 | if stem == str("*"): |
| 1855 | stem = "." |
| 1856 | matches = [] |
| 1857 | for root, dirnames, filenames in os.walk(stem): |
| 1858 | for filename in fnmatch.filter(filenames, file_pattern): |
| 1859 | matches.append(path_join_robust(root, filename)) |
| 1860 | return matches |
| 1861 | |
| 1862 | |
| 1863 | def path_join_robust(path, *paths): |