#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