2
0

file.c 883 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. #define NOBUILD_IMPLEMENTATION
  2. #include "../nobuild.h"
  3. #define DEMO(expr) \
  4. INFO(" "#expr" == %d", expr)
  5. void print_file_recursively(const char *path)
  6. {
  7. INFO(" %s", path);
  8. if (IS_DIR(path)) {
  9. FOREACH_FILE_IN_DIR(file, path, {
  10. const char *child = PATH(path, file);
  11. if (*file != '.') {
  12. print_file_recursively(child);
  13. }
  14. });
  15. }
  16. }
  17. int main(int argc, char *argv[])
  18. {
  19. DEMO(IS_DIR("./nobuild.c"));
  20. DEMO(IS_DIR("./examples"));
  21. DEMO(IS_DIR("./file_that_does_not_exist"));
  22. INFO("Recursively traversing the file system");
  23. print_file_recursively(".");
  24. INFO("Directory removal");
  25. MKDIRS("foo", "bar", "baz");
  26. MKDIRS("foo", "bar", "hello", "world");
  27. print_file_recursively("foo");
  28. RM("foo");
  29. DEMO(IS_DIR("foo"));
  30. return 0;
  31. }