fs.wildcard¶
Match wildcard filenames.
-
fs.wildcard.get_matcher(patterns, case_sensitive)[source]¶ Get a callable that matches names against the given patterns.
Parameters: - patterns (list) – A list of wildcard pattern. e.g.
["*.py", "*.pyc"] - case_sensitive (bool) – If
True, then the callable will be case sensitive, otherwise it will be case insensitive.
Returns: a matcher that will return
Trueif the name given as an argument matches any of the given patterns.Return type: callable
Example
>>> from fs import wildcard >>> is_python = wildcard.get_matcher(['*.py'], True) >>> is_python('__init__.py') True >>> is_python('foo.txt') False
- patterns (list) – A list of wildcard pattern. e.g.
-
fs.wildcard.imatch(pattern, name)[source]¶ Test whether a name matches a wildcard pattern (case insensitive).
Parameters: - pattern (str) – A wildcard pattern, e.g.
"*.py". - name (bool) – A filename.
Returns: Trueif the filename matches the pattern.Return type: bool
- pattern (str) – A wildcard pattern, e.g.
-
fs.wildcard.imatch_any(patterns, name)[source]¶ Test if a name matches any of a list of patterns (case insensitive).
Will return
Trueifpatternsis an empty list.Parameters: - patterns (list) – A list of wildcard pattern, e.g
["*.py", "*.pyc"] - name (str) – A filename.
Returns: Trueif the name matches at least one of the patterns.Return type: bool
- patterns (list) – A list of wildcard pattern, e.g
-
fs.wildcard.match(pattern, name)[source]¶ Test whether a name matches a wildcard pattern.
Parameters: - pattern (str) – A wildcard pattern, e.g.
"*.py". - name (str) – A filename.
Returns: Trueif the filename matches the pattern.Return type: bool
- pattern (str) – A wildcard pattern, e.g.
-
fs.wildcard.match_any(patterns, name)[source]¶ Test if a name matches any of a list of patterns.
Will return
Trueifpatternsis an empty list.Parameters: - patterns (list) – A list of wildcard pattern, e.g
["*.py", "*.pyc"] - name (str) – A filename.
Returns: Trueif the name matches at least one of the patterns.Return type: bool
- patterns (list) – A list of wildcard pattern, e.g