Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
python-imcflibs
Manage
Activity
Members
Labels
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
imcf
python-imcflibs
Commits
49f6011d
Commit
49f6011d
authored
6 years ago
by
Niko Ehrenfeuchter
Browse files
Options
Downloads
Patches
Plain Diff
Add listdir_matching() and image_basename() functions
parent
a401130c
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/imcflibs/pathtools.py
+52
-0
52 additions, 0 deletions
src/imcflibs/pathtools.py
with
52 additions
and
0 deletions
src/imcflibs/pathtools.py
+
52
−
0
View file @
49f6011d
...
...
@@ -74,6 +74,58 @@ def jython_fiji_exists(path):
return
False
def
listdir_matching
(
path
,
suffix
):
"""
Get a list of files in a directory matching a given suffix.
Parameters
----------
path : str
The directory to scan for files.
suffix : str
The suffix to match filenames against.
Returns
-------
list
All file names in the directory matching the suffix (without path!).
"""
matching_files
=
list
()
for
candidate
in
os
.
listdir
(
path
):
if
candidate
.
lower
().
endswith
(
suffix
.
lower
()):
# log.debug("Found file %s", candidate)
matching_files
.
append
(
candidate
)
return
matching_files
def
image_basename
(
orig_name
):
"""
Return the file name component without suffix(es).
Strip away the path and suffix of a given file name, doing a special
treatment for the composite suffix
"
.ome.tif(f)
"
which will be fully
stripped as well.
Parameters
----------
orig_name : str
Example
-------
>>>
image_basename
(
'
/path/to/some_funny_image_file_01.png
'
)
'
some_funny_image_file_01
'
>>>
image_basename
(
'
some-more-complex-stack.ome.tif
'
)
'
some-more-complex-stack
'
>>>
image_basename
(
'
/tmp/FoObAr.OMe.tIf
'
)
'
FoObAr
'
"""
base
=
os
.
path
.
splitext
(
os
.
path
.
basename
(
orig_name
))[
0
]
if
base
.
lower
().
endswith
(
'
.ome
'
):
base
=
base
[:
-
4
]
return
base
# pylint: disable-msg=C0103
# we use the variable name 'exists' in its common spelling (lowercase), so
# removing this workaround will be straightforward at a later point
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment