Issue 36898: Add parameter @case_sensitive to glob and rglob in pathlib
Issue36898
Created on 2019-05-13 07:17 by Chuang Men, last changed 2022-04-11 14:59 by admin.
| Files | ||||
|---|---|---|---|---|
| File name | Uploaded | Description | Edit | |
| pathlib.py | Chuang Men, 2019-05-13 07:17 | |||
| Pull Requests | |||
|---|---|---|---|
| URL | Status | Linked | Edit |
| PR 13274 | closed | SilentGhost, 2019-05-13 07:21 | |
| Messages (3) | |||
|---|---|---|---|
| msg342284 - (view) | Author: Chuang Men (Chuang Men) * | Date: 2019-05-13 07:17 | |
In pathlib, I add a parameter @case_sensitive to glob and rglob.
Sometimes the extension would be in upper case but sometimes it would be lower case, for example: *.tif and *.TIF. So the parameter @case_sensitive may be useful in some cases.
Usage example:
In [1]: from pathlib import Path
In [2]: path = Path('.')
In [3]: for each_file in path.glob('*.tif'):
...: print(each_file)
...:
a.tif
b.tif
In [4]: for each_file in path.rglob('*.TIF'):
...: print(each_file)
...:
c.TIF
TEST/d.TIF
In [5]: for each_file in path.glob('*.TIF', case_sensitive=False):
...: print(each_file)
...:
a.tif
c.TIF
b.tif
In [6]: for each_file in path.rglob('*.TIF', case_sensitive=False):
...: print(each_file)
...:
a.tif
c.TIF
b.tif
TEST/d.TIF
TEST/e.tif
|
|||
| msg342287 - (view) | Author: Serhiy Storchaka (serhiy.storchaka) * ![]() |
Date: 2019-05-13 07:35 | |
You can use the pattern '*.[Tt][Ii][Ff]'. |
|||
| msg342289 - (view) | Author: Chuang Men (Chuang Men) * | Date: 2019-05-13 07:58 | |
It is a good solution but when pattern is long, it might be a little inconvenient. Anyway, just an advice. Thank you for your reply! |
|||
| History | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2022-04-11 14:59:15 | admin | set | github: 81079 |
| 2019-05-13 07:58:11 | Chuang Men | set | messages: + msg342289 |
| 2019-05-13 07:35:59 | serhiy.storchaka | set | nosy:
+ serhiy.storchaka messages: + msg342287 |
| 2019-05-13 07:21:47 | SilentGhost | set | pull_requests:
+ pull_request13179 stage: patch review versions: + Python 3.8, - Python 3.7 |
| 2019-05-13 07:17:56 | Chuang Men | create | |
