slip10and slip23
#include <stdio.h>
#include <dirent.h>
#include <sys/stat.h>
void listFiles(const char *dirPath, long int sizeThreshold) {
DIR *dir;
struct dirent *entry;
struct stat fileStat;
dir = opendir(dirPath);
if (dir == NULL) {
perror("Error opening directory");
return;
}
while ((entry = readdir(dir)) != NULL) {
char fullPath[1024];
snprintf(fullPath, sizeof(fullPath), "%s/%s", dirPath, entry->d_name);
if (stat(fullPath, &fileStat) == -1) {
perror("Error");
continue;
}
if (S_ISREG(fileStat.st_mode) && fileStat.st_size > sizeThreshold) {
printf("%s (%ld bytes)\n", fullPath, fileStat.st_size);
}
if (S_ISDIR(fileStat.st_mode) && strcmp(entry->d_name, ".") != 0 && strcmp(entry->d_name, "..") != 0) {
listFiles(fullPath, sizeThreshold);
}
}
closedir(dir);
}
int main(int argc, char *argv[]) {
if (argc != 2) {
printf("Usage: %s size_threshold\n", argv[0]);
return 1;
}
long int sizeThreshold = atol(argv[1]);
listFiles(".", sizeThreshold);
return 0;
}