diff --git a/io/include/detray/io/csv/intersection2D.hpp b/io/include/detray/io/csv/intersection2D.hpp index 531d75fa2..f9bbbd5b8 100644 --- a/io/include/detray/io/csv/intersection2D.hpp +++ b/io/include/detray/io/csv/intersection2D.hpp @@ -18,6 +18,7 @@ // System include(s). #include +#include namespace detray::io::csv { @@ -120,7 +121,7 @@ inline void write_intersection2D( inters_file_name = io::alt_file_name(file_name); } else { // Make sure the output directories exit - io::create_path(inters_file_name); + io::create_path(std::filesystem::path{inters_file_name}.parent_path()); } dfe::NamedTupleCsvWriter inters_writer( diff --git a/io/include/detray/io/csv/track_parameters.hpp b/io/include/detray/io/csv/track_parameters.hpp index 4592b3d02..53b562963 100644 --- a/io/include/detray/io/csv/track_parameters.hpp +++ b/io/include/detray/io/csv/track_parameters.hpp @@ -16,6 +16,9 @@ #include #include +// System include(s) +#include + namespace detray::io::csv { /// Type to read the data of free track parameters @@ -110,7 +113,7 @@ inline void write_free_track_params( trk_file_name = io::alt_file_name(file_name); } else { // Make sure the output directories exit - io::create_path(trk_file_name); + io::create_path(std::filesystem::path{trk_file_name}.parent_path()); } dfe::NamedTupleCsvWriter track_param_writer( diff --git a/io/include/detray/io/utils/create_path.hpp b/io/include/detray/io/utils/create_path.hpp index 46f667739..aa3f81d09 100644 --- a/io/include/detray/io/utils/create_path.hpp +++ b/io/include/detray/io/utils/create_path.hpp @@ -71,9 +71,8 @@ inline std::string alt_file_name(const std::string& name) { inline auto create_path(const std::string& outdir) { auto path = std::filesystem::path(outdir); - path = std::filesystem::is_directory(path) ? path : path.parent_path(); - if (!std::filesystem::exists(path)) { + if (!path.empty() && !std::filesystem::exists(path)) { if (std::error_code err; !std::filesystem::create_directories(path, err)) { throw std::runtime_error(err.message());