From 831587a74932a4ef3f7801bd40fff3471d5d685c Mon Sep 17 00:00:00 2001 From: Bastian Dehn Date: Tue, 16 Jul 2024 14:28:36 +0200 Subject: [PATCH] add list files and direcotry --- src/main.c | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/src/main.c b/src/main.c index e3bfac7..f4aa356 100644 --- a/src/main.c +++ b/src/main.c @@ -1,7 +1,30 @@ #include +#include +#include -int main() +int main(int argc, char* argv[]) { - printf("Hello World!\n"); + if (argc < 2) { + printf("ERROR: %s \n", argv[0]); + return 1; + } + + glob_t files; + struct stat statbuf; + glob("*", 0, NULL, &files); + + printf("count: %ld\n", files.gl_pathc); + + for (int i = 0; i < files.gl_pathc; i++) { + stat(files.gl_pathv[i], &statbuf); + if (S_ISREG(statbuf.st_mode)) { + printf("filename: %s\n", files.gl_pathv[i]); + } + if (S_ISDIR(statbuf.st_mode)) { + printf("directory: %s\n", files.gl_pathv[i]); + } + } + + globfree(&files); return 0; } \ No newline at end of file -- 2.39.5