fs.glob¶
Useful functions for working with glob patterns.
-
class
fs.glob.
BoundGlobber
(fs: FS)[source]¶ A
Globber
object bound to a filesystem.An instance of this object is available on every Filesystem object as the
glob
property.-
__call__
(pattern: str, path: str = '/', namespaces: Optional[List[str]] = None, case_sensitive: bool = True, exclude_dirs: Optional[List[str]] = None) → Globber[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
-
-
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.
Globber
(fs: FS, pattern: str, path: str = '/', namespaces: Optional[List[str]] = None, case_sensitive: bool = True, exclude_dirs: Optional[List[str]] = None)[source]¶ A generator of glob results.
-
__init__
(fs: FS, pattern: str, path: str = '/', namespaces: Optional[List[str]] = None, case_sensitive: bool = True, exclude_dirs: Optional[List[str]] = None) → None[source]¶ Create a new Globber instance.
- 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__
() → Iterator[GlobMatch][source]¶ Get an iterator of
fs.glob.GlobMatch
objects.
-
count
() → fs.glob.Counts[source]¶ Count files / directories / data in matched paths.
Example
>>> my_fs.glob('**/*.py').count() Counts(files=2, directories=0, data=55)
- Returns
A named tuple containing results.
- Return type
-
-
class
fs.glob.
LineCounts
(lines, non_blank)¶ -
lines
¶ Alias for field number 0
-
non_blank
¶ Alias for field number 1
-
-
fs.glob.
imatch
(pattern: str, path: str) → bool[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: str, path: str) → bool[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