file.c 994 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  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(void)
  18. {
  19. DEMO(IS_DIR("./nobuild.c"));
  20. DEMO(IS_DIR("./examples"));
  21. DEMO(IS_DIR("./file_that_does_not_exist"));
  22. DEMO(PATH_EXISTS("./nobuild.c"));
  23. DEMO(PATH_EXISTS("./examples"));
  24. DEMO(PATH_EXISTS("./file_that_does_not_exist"));
  25. INFO("Recursively traversing the file system");
  26. print_file_recursively(".");
  27. INFO("Directory removal");
  28. MKDIRS("foo", "bar", "baz");
  29. MKDIRS("foo", "bar", "hello", "world");
  30. print_file_recursively("foo");
  31. RM("foo");
  32. DEMO(IS_DIR("foo"));
  33. return 0;
  34. }