PATHTOOLS(3)
πΈ NAME πΈ
okay so bestie, pull up a chair, because this is the PATHTOOLS(3) manual page and it's literally about pathtools β the pathtools Documentation π
It's a Python API library for all your common path and pattern functionality needs. paths? patterns? she does both. no cap. β¨
π EASY INSTALLATION π
ngl the install is giving effortless. you can use pip to get pathtools quickly and easily, like:
$ pip install pathtools
that's it. that's the whole step. slay. π
π API REFERENCE π
π§ pathtools.path
module pathtools.path
synopsis β Directory walking, listing, and path sanitizing functions. π¦
author β Yesudeep Mangalapilly <yesudeep@gmail.com>
β¨ Functions β¨
pathtools.path.get_dir_walker(recursive, topdown=True, followlinks=False)β returns a recursive or a non-recursive directory walker. pick your fighter π- Parameters β
recursive-- True produces a recursive walker; False produces a non-recursive walker. - Returns β A walker function.
- Parameters β
pathtools.path.walk(dir_pathname, recursive=True, topdown=True, followlinks=False)β walks a directory tree, optionally recursively. Works exactly likeos.walk(), only adding therecursiveargument. iconic behavior honestly π- Parameters
dir_pathname-- The directory to traverse.recursive-- True for walking recursively through the directory tree; False otherwise.topdown-- Please see the documentation foros.walk()followlinks-- Please see the documentation foros.walk()
- Parameters
pathtools.path.listdir(dir_pathname, recursive=True, topdown=True, followlinks=False)β enlists all items using their absolute paths in a directory, optionally recursively. π- Parameters
dir_pathname-- The directory to traverse.recursive-- True for walking recursively through the directory tree; False otherwise.topdown-- Please see the documentation foros.walk()followlinks-- Please see the documentation foros.walk()
- Parameters
pathtools.path.list_directories(dir_pathname, recursive=True, topdown=True, followlinks=False)β enlists all the directories using their absolute paths within the specified directory, optionally recursively. directories only, we're being picky π- Parameters
dir_pathname-- The directory to traverse.recursive-- True for walking recursively through the directory tree; False otherwise.topdown-- Please see the documentation foros.walk()followlinks-- Please see the documentation foros.walk()
- Parameters
pathtools.path.list_files(dir_pathname, recursive=True, topdown=True, followlinks=False)β enlists all the files using their absolute paths within the specified directory, optionally recursively. files only bestie, no folders allowed π- Parameters
dir_pathname-- The directory to traverse.recursive-- True for walking recursively through the directory tree; False otherwise.topdown-- Please see the documentation foros.walk()followlinks-- Please see the documentation foros.walk()
- Parameters
pathtools.path.absolute_path(path)β returns the absolute path for the given path and normalizes the path.- Parameters β
path-- Path for which the absolute normalized path will be found. - Returns β Absolute normalized path.
- Parameters β
pathtools.path.real_absolute_path(path)β returns the real absolute normalized path for the given path.- Parameters β
path-- Path for which the real absolute normalized path will be found. - Returns β Real absolute normalized path.
- Parameters β
pathtools.path.parent_dir_path(path)β returns the parent directory path. your path's mother, essentially π«Ά- Parameters β
path-- Path for which the parent directory will be obtained. - Returns β Parent directory path.
- Parameters β
π pathtools.patterns
module pathtools.patterns
synopsis β Wildcard pattern matching and filtering functions for paths. β
author β Yesudeep Mangalapilly <yesudeep@gmail.com>
β¨ Functions β¨
pathtools.patterns.match_path(pathname, included_patterns=None, excluded_patterns=None, case_sensitive=True)β matches a pathname against a set of acceptable and ignored patterns.- Parameters
pathname-- A pathname which will be matched against a pattern.included_patterns-- Allow filenames matching wildcard patterns specified in this list. If no pattern is specified, the function treats the pathname as amatch_path.excluded_patterns-- Ignores filenames matching wildcard patterns specified in this list. If no pattern is specified, the function treats the pathname as amatch_path.case_sensitive-- True if matching should be case-sensitive; False otherwise.
- Returns β True if the pathname matches; False otherwise.
- Raises β ValueError if included patterns and excluded patterns contain the same pattern.
- Doctests::
- Parameters
>>> match_path("/Users/gorakhargosh/foobar.py")
True
>>> match_path("/Users/gorakhargosh/foobar.py", case_sensitive=False)
True
>>> match_path("/users/gorakhargosh/foobar.py", ["*.py"], ["*.PY"], True)
True
>>> match_path("/users/gorakhargosh/FOOBAR.PY", ["*.py"], ["*.PY"], True)
False
>>> match_path("/users/gorakhargosh/foobar/", ["*.py"], ["*.txt"], False)
False
>>> match_path("/users/gorakhargosh/FOOBAR.PY", ["*.py"], ["*.PY"], False)
Traceback (most recent call last):
...
ValueError: conflicting patterns `set(['*.py'])` included and excluded
pathtools.patterns.match_path_against(pathname, patterns, case_sensitive=True)β determines whether the pathname matches any of the given wildcard patterns, optionally ignoring the case of the pathname and patterns.- Parameters
pathname-- A path name that will be matched against a wildcard pattern.patterns-- A list of wildcard patterns tomatch_paththe filename against.case_sensitive-- True if the matching should be case-sensitive; False otherwise.
- Returns β True if the pattern matches; False otherwise.
- Doctests::
- Parameters
>>> match_path_against("/home/username/foobar/blah.py", ["*.py", "*.txt"], False)
True
>>> match_path_against("/home/username/foobar/blah.py", ["*.PY", "*.txt"], True)
False
>>> match_path_against("/home/username/foobar/blah.py", ["*.PY", "*.txt"], False)
True
>>> match_path_against("C:\windows\blah\BLAH.PY", ["*.py", "*.txt"], True)
False
>>> match_path_against("C:\windows\blah\BLAH.PY", ["*.py", "*.txt"], False)
True
pathtools.patterns.filter_paths(pathnames, included_patterns=None, excluded_patterns=None, case_sensitive=True)β filters from a set of paths based on acceptable patterns and ignorable patterns.- Parameters
pathnames-- A list of path names that will be filtered based on matching and ignored patterns.included_patterns-- Allow filenames matching wildcard patterns specified in this list. If no pattern list is specified,["*"]is used as the default pattern, which matches all files.excluded_patterns-- Ignores filenames matching wildcard patterns specified in this list. If no pattern list is specified, no files are ignored.case_sensitive-- True if matching should be case-sensitive; False otherwise.
- Returns β A list of pathnames that matched the allowable patterns and passed through the ignored patterns.
- Doctests::
- Parameters
>>> pathnames = set(["/users/gorakhargosh/foobar.py", "/var/cache/pdnsd.status", "/etc/pdnsd.conf", "/usr/local/bin/python"])
>>> set(filter_paths(pathnames)) == pathnames
True
>>> set(filter_paths(pathnames, case_sensitive=False)) == pathnames
True
>>> set(filter_paths(pathnames, ["*.py", "*.conf"], ["*.status"], case_sensitive=True)) == set(["/users/gorakhargosh/foobar.py", "/etc/pdnsd.conf"])
True
Found a bug in or want a feature added to pathtools? You can fork the official code repository or file an issue ticket at the issue tracker. do it bestie, she'd love the feedback π
- Index
- Module Index
- Search Page
π AUTHOR π
Yesudeep Mangalapilly
π COPYRIGHT π
2010, Yesudeep Mangalapilly
aaaand that's the whole page, bestie π this was pathtools, version 0.1.2, dated Feb 11, 2025 β go forth and walk those directories recursively, you absolute main character πβ¨π
π¦ where this page comes from
- debian trixie: python3-pathtools 0.1.2-7 Β· MIT
- ubuntu questing: python3-pathtools 0.1.2-7
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms