Skip to content

Commit bd8ef98

Browse files
authored
Refactor create_directory to use C++17 filesystem
Updated create_directory function to use C++17 filesystem library for improved directory creation on supported compilers.
1 parent e1937bc commit bd8ef98

1 file changed

Lines changed: 23 additions & 1 deletion

File tree

modules/PhysiCell_settings.cpp

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,16 @@
6464
# #
6565
###############################################################################
6666
*/
67+
68+
#include <version>
69+
70+
#ifdef __cpp_lib_filesystem
71+
#include <filesystem>
72+
#endif
6773

6874
#include <sys/stat.h>
6975
#include "./PhysiCell_settings.h"
76+
#include "../core/PhysiCell_cell.h"
7077

7178
using namespace BioFVM;
7279

@@ -355,15 +362,30 @@ bool create_directories(const std::string &path)
355362
return create_directory(path);
356363
}
357364

365+
#ifdef __cpp_lib_filesystem
358366
bool create_directory(const std::string &path)
359367
{
360-
#if defined(_WIN32)
368+
// Create the directory using C++17 filesystem library
369+
std::error_code ec; // To capture any error
370+
if (std::filesystem::create_directories(path, ec)) {
371+
return true; // Directory created successfully
372+
} else if (ec) {
373+
std::cerr << "Error creating directory " << path << ": " << ec.message() << std::endl;
374+
return false; // An error occurred
375+
}
376+
return true; // Directory already exists
377+
}
378+
#else
379+
bool create_directory(const std::string &path)
380+
{
381+
#if defined(__MINGW32__) || defined(__MINGW64__)
361382
bool success = mkdir(path.c_str()) == 0;
362383
#else
363384
bool success = mkdir(path.c_str(), 0755) == 0;
364385
#endif
365386
return success || errno == EEXIST;
366387
}
388+
#endif
367389

368390
void create_output_directory(const std::string& path)
369391
{

0 commit comments

Comments
 (0)