diff --git a/src/output/GnuplotWriter1D.cpp b/src/output/GnuplotWriter1D.cpp
index bc85f5e4caabb07b838c3cb48cd206d1ab271ebc..a40b068853bfe7b985ebd678fd73467539c70091 100644
--- a/src/output/GnuplotWriter1D.cpp
+++ b/src/output/GnuplotWriter1D.cpp
@@ -216,6 +216,8 @@ GnuplotWriter1D::_write(const MeshType& mesh,
     throw NormalError("cannot store both node and cell data in the same gnuplot file");
   }
 
+  createDirectoryIfNeeded(_getFilename());
+
   std::ofstream fout;
 
   if (parallel::rank() == 0) {
diff --git a/src/output/GnuplotWriterRaw.cpp b/src/output/GnuplotWriterRaw.cpp
index 9e266851e2f57f9d4e1a4c106eb53b09690e0fee..e04a9c797de2525359737c93699425fc252db4fe 100644
--- a/src/output/GnuplotWriterRaw.cpp
+++ b/src/output/GnuplotWriterRaw.cpp
@@ -196,6 +196,8 @@ GnuplotWriterRaw::_write(const MeshType& mesh,
     throw NormalError("cannot store both node and cell data in the same gnuplot file");
   }
 
+  createDirectoryIfNeeded(_getFilename());
+
   std::ofstream fout;
 
   if (parallel::rank() == 0) {