Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python pathlib match function doesn't work

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

>>> from pathlib import Path
>>> 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?

like image 805
no step on snek Avatar asked May 30 '26 18:05

no step on snek


1 Answers

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
like image 120
I.Am.A.Guy Avatar answered Jun 01 '26 10:06

I.Am.A.Guy



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!