On this page
shutil.ignore_patterns
Prev: shutil.get_unpack_formats | Up: shutil | Next: shutil.make_archive
Rel: shutil.chown, shutil.copy, shutil.copy2, shutil.copyfile
Ref: docs.python.org — shutil.ignore_patterns
Tags: #public #python3 #stdlib #shutil
Import
import shutil
from shutil import ignore_patterns
Signature & Overview
shutil.ignore_patterns(*patterns)
Function that can be used as copytree() ignore parameter.
Usage
import shutil
ignorer = shutil.ignore_patterns("*.pyc", "__pycache__", ".git")
skipped = ignorer("/project", ["main.py", "main.pyc", "__pycache__"])
assert skipped == {"main.pyc", "__pycache__"}
Gotchas
- Matches basenames only, not full paths: Patterns use
fnmatchagainst filenames inside each directory visited bycopytree(). - Factory function: Call
ignore_patterns(...)to produce the callback expected bycopytree(..., ignore=...).
REPL Inspect
from shutil import ignore_patterns
help(ignore_patterns)
Linked from
Related notes
- tuts/python3/stdlib_module/shutil/get_unpack_formats Linked here; links to this page; shared tags: #shutil, #stdlib
- tuts/python3/stdlib_module/shutil/make_archive Linked here; links to this page; shared tags: #shutil, #stdlib
- tuts/python3/stdlib_module/shutil Linked here; links to this page; shared tags: #stdlib
- tuts/python3/stdlib_module/shutil/chown Linked here; shared tags: #shutil, #stdlib
- tuts/python3/stdlib_module/shutil/copy Linked here; shared tags: #shutil, #stdlib
- tuts/python3/stdlib_module/shutil/copy2 Linked here; shared tags: #shutil, #stdlib
- tuts/python3/stdlib_module/shutil/copyfile Linked here; shared tags: #shutil, #stdlib
- tuts/python3/stdlib_module/shutil/copyfileobj shared tags: #shutil, #stdlib
- tuts/python3/stdlib_module/shutil/copymode shared tags: #shutil, #stdlib
- tuts/python3/stdlib_module/shutil/copystat shared tags: #shutil, #stdlib