msg225914 - (view) |
Author: João Guerra (joca.bt) |
Date: 2014-08-26 11:37 |
Both fnmatch and glob support the "*/" glob. However, pathlib does not seem to handle this kind of globs correctly. dir = Path("/a/directory/") file = Path("/a/file") print(dir.match("*/")) # True print(file.match("*/")) # True The "/" is being discarded by the match, resulting in incorrect matches. Both the fnmatch and glob libraries support this correct. print(fnmatch("/a/directory/", "*/")) # True print(fnmatch("/a/file", "*/")) # False Issue 21039 may be related to this. |
|
|
msg226033 - (view) |
Author: Antoine Pitrou (pitrou) *  |
Date: 2014-08-28 17:46 |
What is "*/" supposed to do? Only select directories? |
|
|
msg226034 - (view) |
Author: João Guerra (joca.bt) |
Date: 2014-08-28 17:50 |
Yes. |
|
|
msg226036 - (view) |
Author: R. David Murray (r.david.murray) *  |
Date: 2014-08-28 17:58 |
Heh. I never noticed that about shell globs, but it is logical. Learn something new every day. |
|
|
msg226095 - (view) |
Author: Antoine Pitrou (pitrou) *  |
Date: 2014-08-29 22:30 |
Well, it would be logical if pathlib gave special meaning to trailing slashes, which it (still) doesn't :-) I'm still not fond of encoding path characteristics in the path string itself. (and what about symlinks? etc.) |
|
|
msg226102 - (view) |
Author: R. David Murray (r.david.murray) *  |
Date: 2014-08-29 23:07 |
I'm not sure that a trailing '/' is a "path characteristic" in the same sense that a symlink is. Whether the path has a trailing slash or not has meaning both to the user and to the OS. pathlib isn't just modeling actual path objects on the file system, but the abstract concept of a path, and in the abstract context the presence or absence of a trailing '/' as meaning. But that's a wider discussion than this issue :) |
|
|
msg406700 - (view) |
Author: Andrei Kulakov (andrei.avk) *  |
Date: 2021-11-21 02:34 |
I have also run into this when looking into path.glob('dangling_symlink') issue. I can add a few things (in the examples, *myfile* is a file, not a directory): This is probably more common / less obscure than '*/': path.glob('myfile/') => True This is inconsistent with how shell `ls` command works and with glob.glob() and looks wrong. Path('myfile/').exists() => True Path('myfile/') == Path('myfile') => True str(Path('myfile/')) => 'myfile' You can compare this to behavior of `ls` (tested on MacOS): ls myfile myfile ls myfile/ ls: myfile/: Not a directory I think many users will expect behavior consistent with `ls` and `glob.glob`. I've used `ls` in this manner before. |
|
|
msg406701 - (view) |
Author: Andrei Kulakov (andrei.avk) *  |
Date: 2021-11-21 02:35 |
I meant to say: path.glob('myfile/') => [PosixPath('myfile')] |
|
|
msg406702 - (view) |
Author: Andrei Kulakov (andrei.avk) *  |
Date: 2021-11-21 02:47 |
Generally if Path is created with a trailing separator, I think it should error out for all methods that apply to files, for example `.touch()`, `read*()`, `write*()`, others. This is consistent with shell commands: touch xyz/ touch: xyz/: Not a directory echo 'blah' > xyz/ zsh: not a directory: xyz/ |
|
|