This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Add parameter @case_sensitive to glob and rglob in pathlib
Type: enhancement Stage: patch review
Components: Library (Lib) Versions: Python 3.8
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: Chuang Men, serhiy.storchaka
Priority: normal Keywords:

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) * (Python committer) 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:15adminsetgithub: 81079
2019-05-13 07:58:11Chuang Mensetmessages: + msg342289
2019-05-13 07:35:59serhiy.storchakasetnosy: + serhiy.storchaka
messages: + msg342287
2019-05-13 07:21:47SilentGhostsetpull_requests: + pull_request13179
stage: patch review
versions: + Python 3.8, - Python 3.7
2019-05-13 07:17:56Chuang Mencreate