Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
F
fslpy
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Analyze
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
FSL
fslpy
Commits
84118ac7
Commit
84118ac7
authored
3 years ago
by
Paul McCarthy
Browse files
Options
Downloads
Patches
Plain Diff
RF: path.add/remove/splitExt supports pathlib
parent
48a1cda1
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
fsl/utils/path.py
+23
-5
23 additions, 5 deletions
fsl/utils/path.py
with
23 additions
and
5 deletions
fsl/utils/path.py
+
23
−
5
View file @
84118ac7
...
@@ -32,11 +32,17 @@ import os.path as op
...
@@ -32,11 +32,17 @@ import os.path as op
import
os
import
os
import
glob
import
glob
import
operator
import
operator
import
pathlib
import
re
import
re
from
typing
import
Sequence
,
Tuple
,
Union
from
fsl.utils.platform
import
platform
from
fsl.utils.platform
import
platform
PathLike
=
Union
[
str
,
pathlib
.
Path
]
class
PathError
(
Exception
):
class
PathError
(
Exception
):
"""
``Exception`` class raised by the functions defined in this module
"""
``Exception`` class raised by the functions defined in this module
when something goes wrong.
when something goes wrong.
...
@@ -223,19 +229,29 @@ def addExt(prefix,
...
@@ -223,19 +229,29 @@ def addExt(prefix,
return
allPaths
[
0
]
return
allPaths
[
0
]
def
removeExt
(
filename
,
allowedExts
=
None
,
firstDot
=
False
):
def
removeExt
(
filename
:
PathLike
,
allowedExts
:
Sequence
[
str
]
=
None
,
firstDot
:
bool
=
False
)
->
str
:
"""
Returns the base name of the given file name. See :func:`splitExt`.
"""
"""
Returns the base name of the given file name. See :func:`splitExt`.
"""
return
splitExt
(
filename
,
allowedExts
,
firstDot
)[
0
]
return
splitExt
(
filename
,
allowedExts
,
firstDot
)[
0
]
def
getExt
(
filename
,
allowedExts
=
None
,
firstDot
=
False
):
def
getExt
(
filename
:
PathLike
,
allowedExts
:
Sequence
[
str
]
=
None
,
firstDot
:
bool
=
False
)
->
str
:
"""
Returns the extension of the given file name. See :func:`splitExt`.
"""
"""
Returns the extension of the given file name. See :func:`splitExt`.
"""
return
splitExt
(
filename
,
allowedExts
,
firstDot
)[
1
]
return
splitExt
(
filename
,
allowedExts
,
firstDot
)[
1
]
def
splitExt
(
filename
,
allowedExts
=
None
,
firstDot
=
False
):
def
splitExt
(
filename
:
PathLike
,
allowedExts
:
Sequence
[
str
]
=
None
,
firstDot
:
bool
=
False
)
->
Tuple
[
str
,
str
]:
"""
Returns the base name and the extension from the given file name.
"""
Returns the base name and the extension from the given file name.
If ``allowedExts`` is ``None`` and ``firstDot`` is ``False``, this
If ``allowedExts`` is ``None`` and ``firstDot`` is ``False``, this
...
@@ -262,6 +278,8 @@ def splitExt(filename, allowedExts=None, firstDot=False):
...
@@ -262,6 +278,8 @@ def splitExt(filename, allowedExts=None, firstDot=False):
last period. Ignored if ``allowedExts`` is specified.
last period. Ignored if ``allowedExts`` is specified.
"""
"""
filename
=
str
(
filename
)
# If allowedExts is not specified
# If allowedExts is not specified
# we split on a period character
# we split on a period character
if
allowedExts
is
None
:
if
allowedExts
is
None
:
...
...
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