Browse Source

(#3) Add recursive file traversal to the examples

rexim 4 years ago
parent
commit
5ffe5cc99f
1 changed files with 13 additions and 0 deletions
  1. 13 0
      examples/file.c

+ 13 - 0
examples/file.c

@@ -4,10 +4,23 @@
 #define DEMO(expr)                              \
 #define DEMO(expr)                              \
     INFO("    "#expr" == %d", expr)
     INFO("    "#expr" == %d", expr)
 
 
+void print_file_recursively(const char *path)
+{
+    FOREACH_FILE_IN_DIR(file, path, {
+        const char *child = PATH(path, file);
+        INFO("    %s", child);
+        if (*file != '.' && IS_DIR(child)) {
+            print_file_recursively(child);
+        }
+    });
+}
+
 int main(int argc, char *argv[])
 int main(int argc, char *argv[])
 {
 {
     DEMO(IS_DIR("./nobuild.c"));
     DEMO(IS_DIR("./nobuild.c"));
     DEMO(IS_DIR("./examples"));
     DEMO(IS_DIR("./examples"));
     DEMO(IS_DIR("./file_that_does_not_exist"));
     DEMO(IS_DIR("./file_that_does_not_exist"));
+    INFO("Recursively traversing the file system");
+    print_file_recursively(".");
     return 0;
     return 0;
 }
 }