fs.wildcard

Match wildcard filenames.

fs.wildcard.get_matcher(patterns, case_sensitive)

Get a callable that checks a list of names matches the given wildcard 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.
Return type:

callable

Here’s an example:

>>> import wildcard
>>> is_python = wildcard.get_macher(['*.py'])
>>> is_python('__init__.py')
>>> True
>>> is_python('foo.txt')
>>> False
fs.wildcard.imatch(pattern, name)

Test whether name matches pattern, ignoring case differences.

Parameters:
  • pattern (str) – A wildcard pattern. e.g. "*.py"
  • name (str) – A filename
Return type:

bool

fs.wildcard.imatch_any(patterns, name)

Test if a name matches at least one of a list of patterns, ignoring case differences. Will return True if patterns is an empty list.

Parameters:
  • patterns (list) – A list of wildcard pattern. e.g. ["*.py", "*.pyc"]
  • name (str) – A filename.
Return type:

bool

fs.wildcard.match(pattern, name)

Test whether name matches pattern.

Parameters:
  • pattern (str) – A wildcard pattern. e.g. "*.py"
  • name (str) – A filename
Return type:

bool

fs.wildcard.match_any(patterns, name)

Test if a name matches at least one of a list of patterns. Will return True if patterns is an empty list.

Parameters:
  • patterns (list) – A list of wildcard pattern. e.g. ["*.py", "*.pyc"]
  • name (str) – A filename.
Return type:

bool