Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make output folder if it does not exist #309

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions modules/PhysiCell_settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
###############################################################################
*/

#include <sys/stat.h>
#include "./PhysiCell_settings.h"

using namespace BioFVM;
Expand Down Expand Up @@ -108,6 +109,8 @@ bool load_PhysiCell_config_file( std::string filename )

parameters.read_from_pugixml( physicell_config_root );

create_output_directory( PhysiCell_settings.folder );

return true;
}

Expand Down Expand Up @@ -320,6 +323,45 @@ void PhysiCell_Settings::read_from_pugixml( void )
return;
}

bool create_directories(const std::string &path)
{
std::vector<std::string> directories;
size_t pos = 0;
std::string currentPath;

while ((pos = path.find_first_of("/\\", pos)) != std::string::npos) {
currentPath = path.substr(0, pos++);
if (!create_directory(currentPath)) {
return false;
}
}
return create_directory(path);
}

bool create_directory(const std::string &path)
{
#if defined(__MINGW32__) || defined(__MINGW64__)
bool success = mkdir(path.c_str()) == 0;
#else
bool success = mkdir(path.c_str(), 0755) == 0;
#endif
return success || errno == EEXIST;
}

void create_output_directory(const std::string& path)
{
if (!create_directories(path))
{
std::cout << "ERROR: Could not create output directory " << path << " ! Quitting." << std::endl;
exit(-1);
}
}

void create_output_directory(void)
{
create_output_directory(PhysiCell_settings.folder);
}

PhysiCell_Globals PhysiCell_globals;

/* parameters functions */
Expand Down
6 changes: 6 additions & 0 deletions modules/PhysiCell_settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,12 @@ class PhysiCell_Settings
void read_from_pugixml( void );
};

bool create_directories(const std::string &path);
bool create_directory(const std::string &path);

void create_output_directory(const std::string& path);
void create_output_directory(void);

class PhysiCell_Globals
{
private:
Expand Down
Loading