File search and file system traversal

pshell.glob(pathname, *, min_results=0, max_results=None)

Like glob.glob(), but in addition it supports environment variables in pathname, logs the number of results, and incorporates protection from non-existing paths.

Parameters:
  • pathname (str) – bash-like wildcard expression
  • min_results (int) – minimum number of expected results
  • max_results (int) – maximum number of expected results. Omit for no maximum.
Raises:

FileMatchError – if got less results than min_results or more than max_results

pshell.iglob(pathname, *, min_results=0, max_results=None)

Like glob, but returns an iterator instead. Notice that, unlike with glob, you may have time to process some of the results before FileMatchError` is raised.

Also, in case max_results is exceeded, the iteration will stop immediately.

e.g.:

>>> for fname in glob("test*.txt", max_results=2):
>>>    print(fname)
FileMatchError: File match test*.txt produced 4 results, expected up
                to 2

>>> for fname in iglob("test*.txt", max_results=2):
>>>    print(fname)
test1.txt
test2.txt
FileMatchError: File match test*.txt produced 3 or more results,
                expected up to 2
exception pshell.FileMatchError

glob returned not enough or too many matches