I want to use pathlib.glob()
to find directories with a specific name pattern (*data
) in the current working dir. I don't want to explicitly check via .isdir()
or something else.
Input data
This is the relevant listing with three folders as the expected result and one file with the same pattern but that should be part of the result.
ls -ld *data
drwxr-xr-x 2 user user 4,0K 9. Sep 10:22 2021-02-11_68923_data/
drwxr-xr-x 2 user user 4,0K 9. Sep 10:22 2021-04-03_38923_data/
drwxr-xr-x 2 user user 4,0K 9. Sep 10:22 2022-01-03_38923_data/
-rw-r--r-- 1 user user 0 9. Sep 10:24 2011-12-43_3423_data
Expected result
[
'2021-02-11_68923_data/',
'2021-04-03_38923_data/',
'2022-01-03_38923_data/'
]
Minimal working example
from pathlib import Path
cwd = Path.cwd()
result = cwd.glob('*_data/')
result = list(result)
That gives me the 3 folders but also the file.
Also tried the variant cwd.glob('**/*_data/')
.