From 05c5cbdf87bdb31f85eba9744704a80a3121b221 Mon Sep 17 00:00:00 2001 From: Paul McCarthy <pauldmccarthy@gmail.com> Date: Fri, 2 Feb 2018 13:47:10 +0000 Subject: [PATCH] Two more fixes to imcp: - if moving a file from a group, need to remove the entire group - Special test for when dest is a non-existent directory --- fsl/utils/imcp.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/fsl/utils/imcp.py b/fsl/utils/imcp.py index ffb41a4ec..047f1f2f2 100644 --- a/fsl/utils/imcp.py +++ b/fsl/utils/imcp.py @@ -18,6 +18,8 @@ import os import os.path as op import shutil +import nibabel as nib + import fsl.utils.path as fslpath import fsl.data.image as fslimage @@ -53,7 +55,9 @@ def imcp(src, copied. See :func:`immv`. """ - import nibabel as nib + # special case - non-existent directory + if dest.endswith('/') and not op.isdir(dest): + raise fslpath.PathError('Directory does not exist: {}'.format(dest)) if op.isdir(dest): dest = op.join(dest, op.basename(src)) @@ -135,7 +139,13 @@ def imcp(src, nib.save(img, dest) if move: - os.remove(src) + # if input is an image pair, we + # need to remove all input files + srcs = fslpath.getFileGroup(src, + fslimage.ALLOWED_EXTENSIONS, + fslimage.FILE_GROUPS) + for src in srcs: + os.remove(src) return -- GitLab