fs.glob

class fs.glob.BoundGlobber(fs)[source]

A Globber object bound to a filesystem.

An instance of this object is available on every Filesystem object as .glob.

Parameters:fs (FS) – A filesystem object.
__call__(pattern, path='/', namespaces=None, case_sensitive=True, exclude_dirs=None)[source]

Match resources on the bound filesystem againsts a glob pattern.

Parameters:
  • pattern (str) – A glob pattern, e.g. "**/*.py"
  • namespaces (list) – A list of additional info namespaces.
  • case_sensitive (bool) – If True, the path matching will be case sensitive i.e. "FOO.py" and "foo.py" will be different, otherwise path matching will be case insensitive.
  • exclude_dirs (list) – A list of patterns to exclude when searching, e.g. ["*.git"].
Returns:

An object that may be queried for the glob matches.

Return type:

Globber

class fs.glob.Counts(files, directories, data)
data

Alias for field number 2

directories

Alias for field number 1

files

Alias for field number 0

class fs.glob.GlobMatch(path, info)
info

Alias for field number 1

path

Alias for field number 0

class fs.glob.Globber(fs, pattern, path='/', namespaces=None, case_sensitive=True, exclude_dirs=None)[source]

A generator of glob results.

Parameters:
  • fs (FS) – A filesystem object
  • pattern (str) – A glob pattern, e.g. "**/*.py"
  • path (str) – A path to a directory in the filesystem.
  • namespaces (list) – A list of additional info namespaces.
  • case_sensitive (bool) – If True, the path matching will be case sensitive i.e. "FOO.py" and "foo.py" will be different, otherwise path matching will be case insensitive.
  • exclude_dirs (list) – A list of patterns to exclude when searching, e.g. ["*.git"].
__iter__()[source]

An iterator of fs.glob.GlobMatch objects.

count()[source]

Count files / directories / data in matched paths.

Example

>>> import fs
>>> fs.open_fs('~/projects').glob('**/*.py').count()
Counts(files=18519, directories=0, data=206690458)
Returns:A named tuple containing results.
Return type:Counts
count_lines()[source]

Count the lines in the matched files.

Returns:A named tuple containing line counts.
Return type:LineCounts

Example

>>> import fs
>>> fs.open_fs('~/projects').glob('**/*.py').count_lines()
LineCounts(lines=5767102, non_blank=4915110)
remove()[source]

Removed all matched paths.

Returns:Number of file and directories removed.
Return type:int

Example

>>> import fs
>>> fs.open_fs('~/projects/my_project').glob('**/*.pyc').remove()
29
class fs.glob.LineCounts(lines, non_blank)
lines

Alias for field number 0

non_blank

Alias for field number 1

fs.glob.imatch(pattern, path)[source]

Compare a glob pattern with a path (case insensitive).

Parameters:
  • pattern (str) – A glob pattern.
  • path (str) – A path.
Returns:

True if the path matches the pattern.

Return type:

bool

fs.glob.match(pattern, path)[source]

Compare a glob pattern with a path (case sensitive).

Parameters:
  • pattern (str) – A glob pattern.
  • path (str) – A path.
Returns:

True if the path matches the pattern.

Return type:

bool

Example

>>> from fs.glob import match
>>> match("**/*.py", "/fs/glob.py")
True