Quickstart¶
This page walks through one small project so you can see what each call
returns. You need vexy-glob installed (see Installation).
Set up a sample tree¶
-
Create a scratch directory with a few files:
-
Start Python in
play/:
Find files¶
-
Import the package and list the Python files:
>>> import vexy_glob >>> sorted(vexy_glob.find("*.py", as_list=True)) ['./src/a.py', './src/sub/b.py']Three things happened:
*.pyhas no/, so the pattern matched file names at any depth.- Paths start with
./because the defaultrootis".". .hid/c.pyis missing, because hidden files and directories are skipped by default.
-
Include hidden entries:
-
Search below a different root. The paths now start with that root:
-
Stream instead of collecting. Without
as_list=True,find()returns an iterator that yields each path as the walker finds it:The order depends on thread scheduling. Use
sort="path"(which also collects the results into a list) when the order matters. -
Get
pathlib.Pathobjects:On Windows the objects are
WindowsPath.
Filter¶
-
Directories only:
The root directory itself is part of the walk, so
"."appears. -
Files by extension, sorted by file name:
-
Files changed in the last day:
Search contents¶
-
Search for a regular expression in Python files:
>>> vexy_glob.search("TODO", "*.py", as_list=True) [{'path': './src/sub/b.py', 'line_number': 1, 'line_text': 'TODO x\n', 'matches': ['TODO x']}]Each result is a dictionary.
line_textkeeps the line ending. -
Search with a lowercase pattern. Smart case makes it case-insensitive, so it still finds
TODO:
Use the command line¶
The same searches from a shell:
Next steps¶
- Patterns and case explains how patterns meet paths.
- Filters lists every filter and its accepted values.
- Python API is the full reference.