Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 9 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

There are many libraries for traversing directories. You can also do this using the standard library. What makes this library different:

- 💎 Beautiful, laconic syntax.
- ⚗️ Filtering by file extensions, text patterns in [`.gitignore` format](https://git-scm.com/book/en/v2/Git-Basics-Recording-Changes-to-the-Repository#_ignoring), and using custom callables.
- 🐍 Natively works with both [`Path` objects](https://docs.python.org/3/library/pathlib.html#basic-use) from the standard library and strings.
- ❌ Support for [cancellation tokens](https://github.com/pomponchik/cantok).
Expand All @@ -30,7 +31,7 @@ There are many libraries for traversing directories. You can also do this using

- [**Installation**](#installation)
- [**Basic usage**](#basic-usage)
- [**Applying a Function to Each Path**](#applying-a-function-to-each-path)
- [**Applying a function to each path**](#applying-a-function-to-each-path)
- [**Filtering**](#filtering)
- [**Working with Cancellation Tokens**](#working-with-cancellation-tokens)
- [**Combination**](#combination)
Expand Down Expand Up @@ -74,17 +75,17 @@ crawler = Crawler('.', only_files=False)
```


## Applying a Function to Each Path
## Applying a function to each path

If you just want to run a function for each file the crawler finds, you don't have to write the loop yourself — every crawler has an `apply()` method:

```python
from dirstree import PythonCrawler

PythonCrawler('src', exclude=['tests/**']).apply(my_linter)
Crawler('src', exclude=['tests/**']).apply(print)
```

All of the crawler's settings — extensions, excludes, custom filters, and cancellation tokens — are respected, exactly as they would be during normal iteration. You can also pass a fresh cancellation token to `apply()` itself, the same way you would to `go()`.
> ↑ This will print the entire contents of the directory, except for the excluded locations.

> ⓘ All of the crawler's settings are respected, exactly as they would be during normal iteration.


## Filtering
Expand Down Expand Up @@ -137,14 +138,14 @@ You can set an arbitrary condition under which file traversal will stop using [c

1. If you use the crawler as a one-time object for a single iteration, set the token when creating it:

```python
```python
for path in Crawler('.', token=TimeoutToken(0.0001)): # Limit the iteration time to 0.0001 seconds.
print(path)
```

2. If you plan to use the crawler object several times, use the `go()` method for iteration and pass a new token to it every time:

```python
```python
crawler = Crawler('.')

for path in crawler.go(token=TimeoutToken(0.0001)): # Limit the iteration time to 0.0001 seconds.
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"

[project]
name = "dirstree"
version = "0.0.8"
version = "0.0.9"
authors = [{ name = "Evgeniy Blinov", email = "zheni-b@yandex.ru" }]
description = 'Another library for iterating through the contents of a directory'
readme = "README.md"
Expand Down
Loading