MCPcopy
hub / github.com/StevenBlack/hosts / recursive_glob

Function recursive_glob

updateHostsFile.py:1833–1860  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

1831
1832
1833def 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
1863def path_join_robust(path, *paths):

Callers 4

sorted_recursive_globMethod · 0.90
update_sources_dataFunction · 0.85
update_all_sourcesFunction · 0.85
create_initial_fileFunction · 0.85

Calls 1

path_join_robustFunction · 0.85

Tested by 1

sorted_recursive_globMethod · 0.72