forked from tsoding/nobuild
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfile.c
38 lines (31 loc) · 865 Bytes
/
file.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#define NOBUILD_IMPLEMENTATION
#include "../nobuild.h"
#define DEMO(expr) \
INFO(" "#expr" == %d", expr)
void print_file_recursively(const char *path)
{
INFO(" %s", path);
if (IS_DIR(path)) {
FOREACH_FILE_IN_DIR(file, path, {
const char *child = PATH(path, file);
if (*file != '.') {
print_file_recursively(child);
}
});
}
}
int main(void)
{
DEMO(IS_DIR("./nobuild.c"));
DEMO(IS_DIR("./examples"));
DEMO(IS_DIR("./file_that_does_not_exist"));
INFO("Recursively traversing the file system");
print_file_recursively(".");
INFO("Directory removal");
MKDIRS("foo", "bar", "baz");
MKDIRS("foo", "bar", "hello", "world");
print_file_recursively("foo");
RM("foo");
DEMO(IS_DIR("foo"));
return 0;
}