Search code examples
pythonglobpathlib

Python pathlib match function doesn't work


pathlib match(pattern) is documented as matching a path against a provided glob-style pattern but it doesn't work

>>> Path("w/x/y/z").mkdir(parents=True)
>>> list(Path().glob("w/**/z"))
[PosixPath('w/x/y/z')]
>>> Path("w/x/y/z").match("w/**/z")
False

Shouldn't that return true?


Solution

  • Update: Python 3.13

    This feature has finally been added and recursive globs can be used in the full_match() method.

    from pathlib import Path
    
    Path("w/x/y/z").full_match("w/**/z")
    # True