PathFinder
Handsdown API Index / Handsdown / Utils / PathFinder
Auto-generated documentation for handsdown.utils.path_finder module.
PathFinder
Show source in path_finder.py:18
Glob helper for matching paths inside root
path.
With .gitignore
-like include
and exclude
patterns.
Examples
path_finder = PathFinder(Path.cwd())
list(path_finder.glob('*.txt'))
['my_new.txt', 'my.txt', 'new.txt']
list(path_finder.include('my*').glob('*.txt'))
['my_new.txt', 'my.txt']
list(path_finder.exclude('*new*').glob('*.txt'))
['my.txt']
Arguments
root
- Path to root folder.glob_expr
-glob
expression to lookup inroot
Raises
PathFinderError
- Ifroot
is not absolute or not a directory.
Signature
PathFinder().exclude
Show source in path_finder.py:85
Add fnmatch
expression to black list.
If black list is empty - no black list filtration applied.
If expression does not have *
or .
characters, appends /*
to it.
Arguments
fn_exrps
- One or morefnmatch
expressions.
Returns
A copy of itself.
Signature
PathFinder().glob
Show source in path_finder.py:128
Find all matching Path
objects respecting PathFinder().include and PathFinder().exclude patterns.
Yields
Matching Path
objects.
Signature
PathFinder().include
Show source in path_finder.py:64
Add fnmatch
expression to white list.
If white list is empty - no white list filtration applied.
If expression does not have *
or .
characters, appends /*
to it.
Arguments
fn_exrps
- One or morefnmatch
expressions.
Returns
A copy of itself.
Signature
PathFinder().mkdir
Show source in path_finder.py:173
Create directories up to root
if they do not exist.
Arguments
force
- Delete existing parent if it is not a directory.
Raises
PathFinderError
- If any existing parent is not a directory and not inforce
mode.
Signature
PathFinder().relative
Show source in path_finder.py:144
Find a relative path from root
to target
.
target
should be an absolute path.
Arguments
target
- Target path.
Returns
A relative path to target
.