-> % python
Python 3.9.13 | packaged by conda-forge | (main, May 27 2022, 17:00:33)
[Clang 13.0.1 ] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from pathlib import Path
>>> r = Path('.').absolute(); r
PosixPath('/Users/huay/tmp/glob_test')
# a*
>>> for p in r.glob('a*'): print(p)
...
/Users/huay/tmp/glob_test/a1.c
/Users/huay/tmp/glob_test/a3.cpp
/Users/huay/tmp/glob_test/a2.py
# a[13]*
>>> for p in r.glob('a[13]*'): print(p)
...
/Users/huay/tmp/glob_test/a1.c
/Users/huay/tmp/glob_test/a3.cpp
# a[!13]*
>>> for p in r.glob('a[!13]*'): print(p)
...
/Users/huay/tmp/glob_test/a2.py
# *.c*
>>> for p in r.glob('*.c*'): print(p)
...
/Users/huay/tmp/glob_test/a1.c
/Users/huay/tmp/glob_test/a3.cpp
# */*.c*
>>> for p in r.glob('*/*.c*'): print(p)
...
/Users/huay/tmp/glob_test/foo/c2.cpp
/Users/huay/tmp/glob_test/foo/c3.c
# **/*.cpp
>>> for p in r.glob('**/*.cpp'): print(p)
...
/Users/huay/tmp/glob_test/a3.cpp
/Users/huay/tmp/glob_test/foo/c2.cpp
/Users/huay/tmp/glob_test/foo/baz/b3.cpp
/Users/huay/tmp/glob_test/foo/bar/d2.cpp
# *.{py, cp*} Python 不支持
>>> for p in r.glob('*.{py, cp*}'): print(p)
...
# *.?
>>> for p in r.glob('*.?'): print(p)
...
/Users/huay/tmp/glob_test/a1.c
# */*.?
>>> for p in r.glob('*/*.?'): print(p)
...
/Users/huay/tmp/glob_test/foo/c3.c
# */*/*.?
>>> for p in r.glob('*/*/*.?'): print(p)
...
/Users/huay/tmp/glob_test/foo/baz/b2.c
/Users/huay/tmp/glob_test/foo/bar/d3.c