From cc215a2708614d59a2fb4e18e3ccec5ffc812faf Mon Sep 17 00:00:00 2001 From: Daniel Bergman Date: Wed, 23 Oct 2024 00:33:48 -0400 Subject: [PATCH 1/2] handle abspath for output folder creation --- modules/PhysiCell_settings.cpp | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/modules/PhysiCell_settings.cpp b/modules/PhysiCell_settings.cpp index 3937fb8c6..c75a8bd10 100644 --- a/modules/PhysiCell_settings.cpp +++ b/modules/PhysiCell_settings.cpp @@ -325,11 +325,21 @@ void PhysiCell_Settings::read_from_pugixml( void ) bool create_directories(const std::string &path) { - std::vector directories; - size_t pos = 0; + size_t pos = 0; std::string currentPath; - while ((pos = path.find_first_of("/\\", pos)) != std::string::npos) { + // Check for Unix-like absolute path or Windows absolute path with drive letter +#if defined(__MINGW32__) || defined(__MINGW64__) + if (path[0] == '\\') + { pos = 1; } // Windows absolute path starting with backslash + else if (path.length() > 2 && isalpha(path[0]) && path[1] == ':' && path[2] == '\\') + { pos = 3; } // Windows absolute path with drive letter +#else + if (path[0] == '/') + { pos = 1; } // Unix-like absolute path +#endif + + while ((pos = path.find_first_of("/\\", pos)) != std::string::npos) { currentPath = path.substr(0, pos++); if (!create_directory(currentPath)) { return false; From 097d258df4317be00929a7b3526dbd0029da59f9 Mon Sep 17 00:00:00 2001 From: Daniel Bergman Date: Wed, 23 Oct 2024 10:03:42 -0400 Subject: [PATCH 2/2] allow windows users to do what they want --- modules/PhysiCell_settings.cpp | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/modules/PhysiCell_settings.cpp b/modules/PhysiCell_settings.cpp index c75a8bd10..2fe8bbaf7 100644 --- a/modules/PhysiCell_settings.cpp +++ b/modules/PhysiCell_settings.cpp @@ -329,15 +329,14 @@ bool create_directories(const std::string &path) std::string currentPath; // Check for Unix-like absolute path or Windows absolute path with drive letter -#if defined(__MINGW32__) || defined(__MINGW64__) - if (path[0] == '\\') - { pos = 1; } // Windows absolute path starting with backslash - else if (path.length() > 2 && isalpha(path[0]) && path[1] == ':' && path[2] == '\\') - { pos = 3; } // Windows absolute path with drive letter -#else - if (path[0] == '/') - { pos = 1; } // Unix-like absolute path -#endif + if (path[0] == '\\' || path[0] == '/') + { + pos = 1; // Unix-like or Windows absolute path starting with backslash or forward slash + } + else if (path.length() > 2 && isalpha(path[0]) && path[1] == ':' && (path[2] == '\\' || path[2] == '/')) + { + pos = 3; // Windows absolute path with drive letter + } while ((pos = path.find_first_of("/\\", pos)) != std::string::npos) { currentPath = path.substr(0, pos++);