From 9476331a2923c08ae8f62fc83461ffcc72ee9fa3 Mon Sep 17 00:00:00 2001 From: tbaudier Date: Wed, 4 Oct 2017 14:41:40 +0200 Subject: [PATCH] Update SplitFilename function --- common/clitkCommon.cxx | 11 ++++++++--- tools/clitkDicom2Image.cxx | 2 +- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/common/clitkCommon.cxx b/common/clitkCommon.cxx index d1a14bf..55b9927 100644 --- a/common/clitkCommon.cxx +++ b/common/clitkCommon.cxx @@ -19,6 +19,8 @@ #ifndef CLITKCOMMON_CXX #define CLITKCOMMON_CXX +#include + // clitk include #include "clitkCommon.h" @@ -75,9 +77,12 @@ std::string clitk::GetExtension(const std::string& filename) std::vector clitk::SplitFilename(const std::string& filename) { std::vector dirname; - std::size_t found = filename.find_last_of("/\\"); - dirname.push_back(filename.substr(0,found)); - dirname.push_back(filename.substr(found+1,found)); + std::string path = itksys::SystemTools::GetFilenamePath(filename); + std::vector pathComponents; + itksys::SystemTools::SplitPath(filename.c_str(), pathComponents); + std::string fileName = pathComponents.back(); + dirname.push_back(path); + dirname.push_back(fileName); return( dirname ); } //// //------------------------------------------------------------------ diff --git a/tools/clitkDicom2Image.cxx b/tools/clitkDicom2Image.cxx index e08f0de..4e8b268 100644 --- a/tools/clitkDicom2Image.cxx +++ b/tools/clitkDicom2Image.cxx @@ -228,7 +228,7 @@ int main(int argc, char * argv[]) std::ostringstream name; std::vector directory = clitk::SplitFilename(args_info.output_arg); if (directory.size() == 2) - name << directory[0] << *sn << "_" << directory[1]; + name << directory[0] << "/" << *sn << "_" << directory[1]; else name << *sn << "_" << args_info.output_arg; outfile = name.str(); -- 2.47.1