You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Add parameter @case_sensitive to glob and rglob in pathlib #81079
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:
assignee=Noneclosed_at=Nonecreated_at=<Date2019-05-13.07:17:56.195>labels= ['3.8', 'type-feature', 'library']
title='Add parameter @case_sensitive to glob and rglob in pathlib'updated_at=<Date2019-05-13.07:58:11.844>user='https://bugs.python.org/ChuangMen'
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
Activity
ChuangMen commentedon May 13, 2019
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
serhiy-storchaka commentedon May 13, 2019
You can use the pattern '*.[Tt][Ii][Ff]'.
ChuangMen commentedon May 13, 2019
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!
pythonGH-77609: Support following symlinks in `pathlib.Path.glob()`
barneygale commentedon Mar 12, 2023
This should be straightforward to add once #102616 lands.
pythonGH-81079: Add case_sensitive argument to pathlib.Path.glob()
barneygale commentedon Mar 15, 2023
PR available: #102710
Merge branch 'main' into pythongh-81079-glob-case-sensitive-arg-2
Merge branch 'main' into pythongh-81079-glob-case-sensitive-arg-2
Merge branch 'main' into pythongh-81079-glob-case-sensitive-arg-2
Merge branch 'main' into pythongh-81079-glob-case-sensitive-arg-2
pythonGH-104114: Fix `pathlib.WindowsPath.glob()` use of literal patt…
GH-104114: Fix `pathlib.WindowsPath.glob()` use of literal pattern se…
Merge branch 'main' into pythongh-81079-glob-case-sensitive-arg-2
GH-81079: Add case_sensitive argument to `pathlib.Path.glob()` (GH-10…
barneygale commentedon May 4, 2023
Implemented in 3.12: #102710 / 8100be5
Merge branch 'main' into inlinecomp2