How to prevent pathlibs Path.glob from returning files when glob ends with a slash?
The new Path.glob
one pathlib
seems to be different from the old glob.glob
one when the glob pattern ends with a slash.
In [1]: from pathlib import Path
In [2]: from glob import glob
In [3]: glob('webroot/*/')
Out[3]: ['webroot/2017-06-07/']
In [4]: list(Path().glob('webroot/*/'))
Out[4]:
[PosixPath('webroot/.keep'),
PosixPath('webroot/2017-06-07'),
PosixPath('webroot/matches.2017-06-07.json')]
Is this by design some kind of compatibility issue that I am facing? And is there a way to stop it from doing this?
At the moment Ill is working with him:
[path for path in Path().glob('webroot/*/') if path.is_dir()]
+3
source to share