diff --git a/Applications/CLI/ogs.cpp b/Applications/CLI/ogs.cpp
index 9c44b21ec0e43eb91975d0863a13efb7bcd6bc45..46c0e3cf81e9d5f8754f18ea8f769ad7eeb0e767 100644
--- a/Applications/CLI/ogs.cpp
+++ b/Applications/CLI/ogs.cpp
@@ -11,13 +11,12 @@
  *
  */
 
-#include <algorithm>
 #include <pybind11/pybind11.h>
 #include <spdlog/spdlog.h>
 #include <tclap/CmdLine.h>
 
+#include <algorithm>
 #include <chrono>
-#include <filesystem>
 #include <sstream>
 
 #include "CommandLineArgumentParser.h"
@@ -36,6 +35,7 @@
 #include "Applications/ApplicationsLib/TestDefinition.h"
 #include "BaseLib/DateTools.h"
 #include "BaseLib/Error.h"
+#include "BaseLib/FileTools.h"
 #include "BaseLib/Logging.h"
 #include "BaseLib/RunTime.h"
 #include "InfoLib/GitInfo.h"
@@ -67,20 +67,7 @@ int main(int argc, char* argv[])
     INFO("This is OpenGeoSys-6 version {:s}.",
          GitInfoLib::GitInfo::ogs_version);
 
-    if (cli_arg.outdir.length() > 0)
-    {
-        std::error_code mkdir_err;
-        if (std::filesystem::create_directories(cli_arg.outdir, mkdir_err))
-        {
-            INFO("Output directory {:s} created.", cli_arg.outdir);
-        }
-        else if (mkdir_err.value() != 0)
-        {
-            WARN(
-                "Could not create output directory {:s}. Error code {:d}, {:s}",
-                cli_arg.outdir, mkdir_err.value(), mkdir_err.message());
-        }
-    }
+    BaseLib::createOutputDirectory(cli_arg.outdir);
 
     {
         auto const start_time = std::chrono::system_clock::now();
diff --git a/Applications/Utils/ModelPreparation/PartitionMesh/PartitionMesh.cpp b/Applications/Utils/ModelPreparation/PartitionMesh/PartitionMesh.cpp
index 8556e31d77750b91fc1df5f976dccf7847968cdc..daa2aa43cd3ea0fe8e9de0e1c61a12f2119dc7ef 100644
--- a/Applications/Utils/ModelPreparation/PartitionMesh/PartitionMesh.cpp
+++ b/Applications/Utils/ModelPreparation/PartitionMesh/PartitionMesh.cpp
@@ -15,8 +15,6 @@
 #include <spdlog/spdlog.h>
 #include <tclap/CmdLine.h>
 
-#include <filesystem>
-
 #ifdef USE_PETSC
 #include <mpi.h>
 #endif
@@ -118,20 +116,7 @@ int main(int argc, char* argv[])
         });
 
     const auto output_directory = output_directory_arg.getValue();
-    if (output_directory.length() > 0)
-    {
-        std::error_code mkdir_err;
-        if (std::filesystem::create_directories(output_directory, mkdir_err))
-        {
-            INFO("Output directory {:s} created.", output_directory);
-        }
-        else if (mkdir_err.value() != 0)
-        {
-            WARN(
-                "Could not create output directory {:s}. Error code {:d}, {:s}",
-                output_directory, mkdir_err.value(), mkdir_err.message());
-        }
-    }
+    BaseLib::createOutputDirectory(output_directory);
 
     BaseLib::RunTime run_timer;
     run_timer.start();
diff --git a/BaseLib/FileTools.cpp b/BaseLib/FileTools.cpp
index 0afffba21602c1261e76ff73b578bb6ae428789c..060a849d73e52077a330461e028eeedb7239e813 100644
--- a/BaseLib/FileTools.cpp
+++ b/BaseLib/FileTools.cpp
@@ -256,6 +256,27 @@ void removeFiles(std::vector<std::string> const& files)
     }
 }
 
+bool createOutputDirectory(std::string const& dir)
+{
+    if (dir.length() > 0)
+    {
+        std::error_code mkdir_err;
+        if (std::filesystem::create_directories(dir, mkdir_err))
+        {
+            INFO("Output directory {:s} created.", dir);
+        }
+        else if (mkdir_err.value() != 0)
+        {
+            WARN(
+                "Could not create output directory {:s}. Error code {:d}, {:s}",
+                dir, mkdir_err.value(), mkdir_err.message());
+            return false;
+        }
+        return true;
+    }
+    return false;
+}
+
 template <typename T>
 T readBinaryValue(std::istream& in)
 {
diff --git a/BaseLib/FileTools.h b/BaseLib/FileTools.h
index 523e87d10cb113f7e0c10b2d50f82ea7a6b55443..216c40afa8de71a8923e6ab3f6f4cb624f6fca7a 100644
--- a/BaseLib/FileTools.h
+++ b/BaseLib/FileTools.h
@@ -153,4 +153,7 @@ void removeFile(std::string const& filename);
 /// Remove files. If a file does not exist nothing will happen, other errors
 /// lead to OGS_FATAL call.
 void removeFiles(std::vector<std::string> const& files);
+
+// Creates the given directory. Returns true on success.
+bool createOutputDirectory(std::string const& dir);
 }  // end namespace BaseLib