From 50857ded20c99ed943809e85092de88f5c1de128 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lia=20Br=C3=BCggemann?= Date: Fri, 3 Oct 2025 19:59:31 +0200 Subject: [PATCH] added main --- main.c | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 main.c diff --git a/main.c b/main.c new file mode 100644 index 0000000..302f37d --- /dev/null +++ b/main.c @@ -0,0 +1,45 @@ +#include /* for printf and stderr */ +#include /* for strerror */ +#include /* for DIR, opendir, readdir, and dirent */ +#include /* for errno */ +#include /* for stat */ + +int main(int argc, char **argv) +{ + DIR* FD; /* represent the directory */ + struct dirent* in_file; /* represent the file */ + char* target_dir = "."; /* current directory */ + + /* Scanning the target directory */ + FD = opendir(target_dir); + if (FD == NULL) + { + fprintf(stderr, "Error: Failed to open input directory - %s\n", strerror(errno)); + return 1; + } + + /* Reading object (files, directories ...) from the folder */ + while ((in_file = readdir(FD))) + { + struct stat buffer; + int status; + + status = stat(in_file->d_name, &buffer); + /* check status */ + if (status == -1) + { + fprintf(stderr, "Error: Failed to stat item - %s\n", strerror(errno)); + return 1; + } + /* check result */ + if ( buffer.st_mode & S_IFREG ) + { + printf("%s is file \n", in_file->d_name); + } + } + + /* Close the directory */ + closedir(FD); + + return 0; +}