Skip to content

Commit 0800402

Browse files
committed
New optional argument "sort" for listdir_matching()
1 parent 03bfd3a commit 0800402

2 files changed

Lines changed: 9 additions & 1 deletion

File tree

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,4 +47,6 @@
4747
* OME-TIFF filenames are now treated as special cases in the sense that the
4848
`.ome` part is stripped from the `basename` key and added to the `ext` key
4949
instead (as it is part of the suffix).
50+
* `imcflibs.pathtools.listdir_matching` now has an additional optional argument
51+
`sort` (defaulting to `False`) to request the resulting list to be sorted.
5052
* Many improvements / clarifications in function docstrings.

src/imcflibs/pathtools.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ def jython_fiji_exists(path):
155155
return False
156156

157157

158-
def listdir_matching(path, suffix, fullpath=False):
158+
def listdir_matching(path, suffix, fullpath=False, sort=False):
159159
"""Get a list of files in a directory matching a given suffix.
160160
161161
Parameters
@@ -168,6 +168,9 @@ def listdir_matching(path, suffix, fullpath=False):
168168
If set to True, the list returned by the function will contain the full
169169
paths to the matching files (the default is False, which will result in
170170
the file names only, without path).
171+
sort : bool, optional
172+
If set to True, the returned list will be sorted using Python's built-in
173+
`sorted()` call. By default False.
171174
172175
Returns
173176
-------
@@ -183,6 +186,9 @@ def listdir_matching(path, suffix, fullpath=False):
183186
else:
184187
matching_files.append(candidate)
185188

189+
if sort:
190+
matching_files = sorted(matching_files)
191+
186192
return matching_files
187193

188194

0 commit comments

Comments
 (0)