]> gitweb.hhaalo.de Git - mv_none_space.git/commitdiff
add list files and direcotry
authorBastian Dehn <hhaalo@arcor.de>
Tue, 16 Jul 2024 12:28:36 +0000 (14:28 +0200)
committerBastian Dehn <hhaalo@arcor.de>
Tue, 16 Jul 2024 12:28:36 +0000 (14:28 +0200)
src/main.c

index e3bfac72d350ae7d3c33965488710164484a0ca8..f4aa35635678f4a830e3db4a1b05ff096e47fad5 100644 (file)
@@ -1,7 +1,30 @@
 #include <stdio.h>
+#include <sys/stat.h>
+#include <glob.h>
 
-int main()
+int main(int argc, char* argv[])
 {
-       printf("Hello World!\n");
+       if (argc < 2) {
+               printf("ERROR: %s <dir>\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