commit 4a1e49a5d0777a3e823825ec5a90192347401445
parent 852660d63b5cfff1f564de1cd58a776b6b3d0560
Author: Henry Unite <unitehenry@gmail.com>
Date: Thu, 9 Apr 2026 03:53:06 +0000
feat: create subdirectories
Diffstat:
3 files changed, 41 insertions(+), 0 deletions(-)
diff --git a/src/create_subdirectories.c b/src/create_subdirectories.c
@@ -0,0 +1,36 @@
+#include <sys/stat.h>
+#include <unistd.h>
+#include <string.h>
+#include <stdlib.h>
+
+void create_subdirectories(char *filepath) {
+ char *path_copy = strdup(filepath);
+
+ if (!path_copy) return;
+
+ char *last_slash = strrchr(path_copy, '/');
+
+ if (last_slash) {
+ *last_slash = '\0';
+ } else {
+ free(path_copy);
+
+ return;
+ }
+
+ char *p;
+
+ for (p = path_copy + 1; *p; p++) {
+ if (*p == '/') {
+ *p = '\0';
+
+ mkdir(path_copy, 0755);
+
+ *p = '/';
+ }
+ }
+
+ mkdir(path_copy, 0755);
+
+ free(path_copy);
+}
diff --git a/src/create_subdirectories.h b/src/create_subdirectories.h
@@ -0,0 +1 @@
+void create_subdirectories(char *filepath);
+\ No newline at end of file
diff --git a/src/main.c b/src/main.c
@@ -1,3 +1,4 @@
+#include "create_subdirectories.h"
#include "string_list.h"
#include "string_replace.h"
#include <dirent.h>
@@ -78,6 +79,8 @@ void generate_pages(StringList *list) {
printf("filepath: %s\n", write_path);
+ create_subdirectories(write_path);
+
// open file to write
i++;