API Reference¶
Auto-generated from docstrings via mkdocstrings.
Modern API¶
rglob.rglob.find(base, patterns='*', *, exclude=(), max_depth=None, hidden=False, follow_symlinks=False, case_sensitive=None, sort=True, on_error='warn', kinds=(), min_size=None, max_size=None, newer_than=None, older_than=None, newer_than_file=None, perm=None, uid=None, gid=None, respect_gitignore=False)
¶
Recursively yield filesystem entries matching patterns under base.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
base
|
str | PathLike[str]
|
Root directory to walk. |
required |
patterns
|
str | Sequence[str]
|
Glob pattern or sequence of patterns. |
'*'
|
exclude
|
str | Sequence[str]
|
Pattern or patterns to exclude. Same syntax as |
()
|
max_depth
|
int | None
|
Maximum recursion depth. |
None
|
hidden
|
bool
|
When |
False
|
follow_symlinks
|
bool
|
When |
False
|
case_sensitive
|
bool | None
|
Force case-sensitive ( |
None
|
sort
|
bool
|
When |
True
|
on_error
|
OnError
|
How to handle |
'warn'
|
kinds
|
Iterable[Kind]
|
Iterable of |
()
|
min_size
|
int | float | str | None
|
Minimum file size as bytes ( |
None
|
max_size
|
int | float | str | None
|
Maximum file size — same format as |
None
|
newer_than
|
datetime | timedelta | str | None
|
Only yield entries with mtime strictly after this
timestamp. Accepts :class: |
None
|
older_than
|
datetime | timedelta | str | None
|
Only yield entries with mtime strictly before this
timestamp — same format as |
None
|
newer_than_file
|
str | PathLike[str] | None
|
Only yield entries with mtime strictly after this file's mtime. |
None
|
perm
|
int | str | None
|
POSIX permission filter. Plain values require exact mode,
|
None
|
uid
|
int | None
|
POSIX owner uid filter. |
None
|
gid
|
int | None
|
POSIX owner gid filter. |
None
|
respect_gitignore
|
bool
|
When |
False
|
Yields:
| Type | Description |
|---|---|
Path
|
class: |
Path
|
order when |
Examples:
>>> from rglob import find
>>> list(find("/tmp", "*.txt"))
>>> list(find("/tmp", ["*.py", "*.pyx"]))
>>> list(find(".", "**/test_*.py"))
rglob.rglob.find_all(base, patterns='*', **kwargs)
¶
Eager variant of :func:find — returns list[Path].
Legacy API (still supported)¶
rglob.rglob.rglob(base, pattern)
¶
Recursively glob entries under base matching pattern.
Breaking change in 2.0: now returns list[Path] (was list[str]
in 1.x). See the migration guide and ADR-0003 for context. To restore
the old behaviour locally:
paths = [str(p) for p in rglob(base, pattern)]
rglob.rglob.rglob_(pattern)
¶
Recursively glob entries under the current working directory.
rglob.rglob.lcount(base, pattern, func=lambda _line: True)
¶
Count lines across files matching pattern under base.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
base
|
str | PathLike[str]
|
root directory to walk. |
required |
pattern
|
str
|
glob pattern (e.g. |
required |
func
|
Callable[[str], bool]
|
per-line predicate; only lines for which it returns truthy are counted. Defaults to "count every line". |
lambda _line: True
|
Returns:
| Type | Description |
|---|---|
int
|
Integer total line count. |
rglob.rglob.tsize(base, pattern, func=megabytes)
¶
Sum the total size of files matching pattern under base.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
base
|
str | PathLike[str]
|
root directory to walk. |
required |
pattern
|
str
|
glob pattern (e.g. |
required |
func
|
Callable[[float], float]
|
unit-conversion function from bytes to the desired unit.
Defaults to :func: |
megabytes
|
Returns:
| Type | Description |
|---|---|
float
|
The total size converted by |
Unit helpers¶
rglob.rglob.kilobytes(value)
¶
Convert bytes to kibibytes (KiB).
rglob.rglob.megabytes(value)
¶
Convert bytes to mebibytes (MiB).
rglob.rglob.gigabytes(value)
¶
Convert bytes to gibibytes (GiB).
rglob.rglob.terabytes(value)
¶
Convert bytes to tebibytes (TiB).
Path return at 2.0
As of 2.0, rglob() / rglob_() return list[Path] (previously
list[str]). See migrating to 2.0 for the
one-line migration. The new find() / find_all() family already
returns Path so code targeting the modern API doesn't need to change.