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
16 changes: 9 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,6 @@ for file in crawler:

> ↑ This recursively prints all files in the current directory, including files in nested directories. At each iteration, we get a new [`Path` object](https://docs.python.org/3/library/pathlib.html#basic-use).

By default, crawlers iterate over files only. If you need every filesystem entity found under the base directory, pass `only_files=False`:

```python
crawler = Crawler('.', only_files=False)
```


## Applying a function to each path

Expand All @@ -90,6 +84,12 @@ Crawler('src', exclude=['tests/**']).apply(print)

## Filtering

By default, crawlers iterate over files only. If you need every filesystem entity found under the base directory, pass `only_files=False`:

```python
crawler = Crawler('.', only_files=False)
```

Iterating through the files in the directory, you may not want to view all files, but only files of a certain type. To do this, ignore all other files. How to do it? There are three ways:

- Bypass only files with the specified [extensions](https://en.wikipedia.org/wiki/Filename_extension), such as `.txt`, `.doc`, or `.py`.
Expand All @@ -105,7 +105,7 @@ To set the file extensions you are interested in, use the `extensions` parameter
crawler = Crawler('.', extensions=['.txt']) # Iterate only on .txt files.
```

> ⓘ The `extensions` parameter is available only in the default file-only mode, so it cannot be combined with `only_files=False`. `PythonCrawler` is always file-only.
> ⓘ The `extensions` parameter is available only in the default file-only mode, so it cannot be combined with `only_files=False`.

Also, if you only need Python files, you can use a special class to bypass them only, without specifying extensions:

Expand All @@ -115,6 +115,8 @@ from dirstree import PythonCrawler
crawler = PythonCrawler('.') # Iterate only on .py files.
```

> ⓘ `PythonCrawler` is always file-only.

To specify which files and directories you do NOT want to iterate over, use the `exclude` parameter:

```python
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.9"
version = "0.0.10"
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