diff --git a/src/common_io.c b/src/common_io.c
index 652291a16e4f3a01f76c8bed2973c2a5fc32a6ff..aba1595df6d59d13f0e1a1e2f879f4ab2248de84 100644
--- a/src/common_io.c
+++ b/src/common_io.c
@@ -45,6 +45,7 @@
 #include "star_formation_io.h"
 #include "stars_io.h"
 #include "threadpool.h"
+#include "tools.h"
 #include "tracers_io.h"
 #include "units.h"
 #include "velociraptor_io.h"
@@ -2479,3 +2480,15 @@ void io_write_output_field_parameter(const char* filename) {
       "'%s'.\n",
       filename);
 }
+
+/**
+ * @brief Create the subdirectory for snapshots if the user demanded one.
+ *
+ * @param dirname The name of the directory.
+ */
+void io_make_snapshot_subdir(const char* dirname) {
+
+  if (strnlen(dirname, PARSER_MAX_LINE_SIZE) > 0) {
+    safe_checkdir(dirname, /*create=*/1);
+  }
+}
diff --git a/src/common_io.h b/src/common_io.h
index 0fe2427d53e404914e2769313064d466cb667e0d..bb1564cee5b673b0e8526401868de0855a10c194 100644
--- a/src/common_io.h
+++ b/src/common_io.h
@@ -172,4 +172,6 @@ void io_check_output_fields(const struct swift_params* params,
 
 void io_write_output_field_parameter(const char* filename);
 
+void io_make_snapshot_subdir(const char* dirname);
+
 #endif /* SWIFT_COMMON_IO_H */
diff --git a/src/engine.c b/src/engine.c
index 487e5cdcf3b70858a7b68e716a669fd15d909015..a2622f70d280abed2511e35f1d7fb7f15daf6273 100644
--- a/src/engine.c
+++ b/src/engine.c
@@ -3596,13 +3596,6 @@ void engine_dump_snapshot(struct engine *e) {
       error(
           "FILENAME_BUFFER_SIZE is too small for snapshot path and file name");
     }
-      /* Try to ensure the directory exists */
-#ifdef WITH_MPI
-    if (engine_rank == 0) mkdir(e->snapshot_subdir, 0777);
-    MPI_Barrier(MPI_COMM_WORLD);
-#else
-    mkdir(e->snapshot_subdir, 0777);
-#endif
   } else {
     if (snprintf(snapshotBase, FILENAME_BUFFER_SIZE, "%s",
                  e->snapshot_base_name) >= FILENAME_BUFFER_SIZE) {
@@ -4458,6 +4451,9 @@ void engine_config(int restart, int fof, struct engine *e,
       }
     }
 
+    /* Try to ensure the snapshot directory exists */
+    if (e->nodeID == 0) io_make_snapshot_subdir(e->snapshot_subdir);
+
     /* Get the total mass */
     e->total_mass = 0.;
     for (size_t i = 0; i < e->s->nr_gparts; ++i)