-
-
Notifications
You must be signed in to change notification settings - Fork 31.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
pathlib .glob('*/') returns files as well as directories #77573
Comments
Path.cwd().glob('/*') seems to yield all files and folders in cwd, the same as .glob('*'). I believe that glob('*/') should yield only directories, and glob('*') all files and directories. this behaviour isnt documented one way or the other. But it would be consistent with glob.glob() console dump follows: Python 3.6.5 |Anaconda custom (64-bit)| (default, Mar 29 2018, 13:14:23) In [1]: import os In [2]: from pathlib import Path In [6]: import glob In [13]: list(p.glob('*/')) In [14]: list(p.glob('*')) In [15]: glob.glob(os.path.join(str(p), '*/')) In [16]: glob.glob(os.path.join(str(p), '*')) |
this is workaroundable via constructions like: list(x for x in p.glob('*/') if x.is_dir()) but I think there's value in behaving like glob.glob(), and keystroke avoidance for what must be a fairly common use case |
Good find -- I agree that when using Path.cwd().glob('*/'), it should only return directories. This follows the original glob library's functionality as well as the Unix expectation (I believe Windows as well, but I'll double check). I'll work on a fix! |
I checked this on Mac and Windows, pathlib and the old glob std lib behave On Tue, 1 May 2018, 18:35 Emily Morehouse, <report@bugs.python.org> wrote:
|
This appears to be a duplicate of bpo-22276 |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: