diff --git a/fsl/scripts/imrm.py b/fsl/scripts/imrm.py index 2db901882a9c038daecfd421bcebc80cc4fcff3c..bd81103325b6d8dea25f0b88f02c3bbb40555f6c 100644 --- a/fsl/scripts/imrm.py +++ b/fsl/scripts/imrm.py @@ -23,7 +23,7 @@ with warnings.catch_warnings(): import fsl.data.image as fslimage -usage = """Usage: {} <list of image names to remove> +usage = """Usage: imrm <list of image names to remove> NB: filenames can be basenames or not """.strip() @@ -36,14 +36,13 @@ def main(argv=None): """Removes all images which are specified on the command line. """ if argv is None: - argv = sys.argv + argv = sys.argv[1:] - if len(argv) < 2: - exe = op.abspath(argv[0]) - print(usage.format(exe)) + if len(argv) < 1: + print(usage) return 1 - prefixes = [fslpath.removeExt(p, ALLOWED_EXTENSIONS) for p in argv[1:]] + prefixes = [fslpath.removeExt(p, ALLOWED_EXTENSIONS) for p in argv] for prefix, ext in it.product(prefixes, ALLOWED_EXTENSIONS): diff --git a/fsl/scripts/remove_ext.py b/fsl/scripts/remove_ext.py new file mode 100644 index 0000000000000000000000000000000000000000..fc21094ff113576cc808f25fc3dbde1b7f38ff4f --- /dev/null +++ b/fsl/scripts/remove_ext.py @@ -0,0 +1,51 @@ +#!/usr/bin/env python +# +# remove_ext.py - Remove file extensions from NIFTI image paths +# +# Author: Paul McCarthy <pauldmccarthy@gmail.com> +# + + +import sys +import warnings + +import fsl.utils.path as fslpath + +# See atlasq.py for explanation +with warnings.catch_warnings(): + warnings.filterwarnings("ignore", category=FutureWarning) + import fsl.data.image as fslimage + + +usage = """Usage: remove_ext <list of image paths to remove extension from> +""".strip() + + +ALLOWED_EXTENSIONS = fslimage.ALLOWED_EXTENSIONS + ['.mnc', '.mnc.gz'] +"""List of file extensions that are removed by ``remove_ext``. """ + + +def main(argv=None): + """Removes file extensions from all paths which are specified on the + command line. + """ + + if argv is None: + argv = sys.argv[1:] + + if len(argv) < 1: + print(usage) + return 1 + + removed = [] + + for path in argv: + removed.append(fslpath.removeExt(path, ALLOWED_EXTENSIONS)) + + print(' '.join(removed)) + + return 0 + + +if __name__ == '__main__': + sys.exit(main())