Commit 8325b14d authored by VAN TOLL Wouter's avatar VAN TOLL Wouter

- HelperFunctions::CreateDirectoryIfNonExistent() should now work for paths with subfolders.

- Now ignoring the output and screenshots folders.
parent c4fd37f7
......@@ -44,3 +44,7 @@ CMakeLists.txt.user*
# Documentation files generated by Doxygen
/html
# UMANS simulation output
/output
/screenshots
\ No newline at end of file
......@@ -184,18 +184,28 @@ namespace HelperFunctions
bool CreateDirectoryIfNonExistent(const std::string& dirname)
{
// if the directory does not yet exist, try to create it
if (!DirectoryExists(dirname))
// if dirname contains a sequence of folders, try to create it step by step
size_t index = dirname.find_first_of("/");
do
{
int nError = 0;
const std::string& dirpart = dirname.substr(0, index);
// if the directory does not yet exist, try to create it
if (!DirectoryExists(dirpart))
{
int nError = 0;
#if defined(_WIN32)
nError = _mkdir(dirname.c_str()); // can be used on Windows
nError = _mkdir(dirpart.c_str()); // can be used on Windows
#else
mode_t nMode = 0733;
nError = mkdir(dirname.c_str(), nMode); // can be used on non-Windows
mode_t nMode = 0733;
nError = mkdir(dirpart.c_str(), nMode); // can be used on non-Windows
#endif
return (nError == 0);
}
if (nError != 0)
return false;
}
index = dirname.find_first_of("/", index+1);
} while (index != std::string::npos);
return true;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment