remove_ext.py 1.01 KB
Newer Older
1
2
3
4
5
6
7
8
#!/usr/bin/env python
#
# remove_ext.py - Remove file extensions from NIFTI image paths
#
# Author: Paul McCarthy <pauldmccarthy@gmail.com>
#


9
import                   sys
10
11
12
13
14
15
16
import fsl.utils.path as fslpath


usage = """Usage: remove_ext <list of image paths to remove extension from>
""".strip()


17
18
19
20
21
22
23
24
# This list is defined in the
# fsl.data.image class, but are duplicated
# here for performance (to avoid import of
# nibabel/numpy/etc).
exts = ['.nii.gz', '.nii',
        '.img',    '.hdr',
        '.img.gz', '.hdr.gz',
        '.mnc',    '.mnc.gz']
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
"""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:
43
        removed.append(fslpath.removeExt(path, exts))
44
45
46
47
48
49
50
51

    print(' '.join(removed))

    return 0


if __name__ == '__main__':
    sys.exit(main())