-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path010_files_bigger_n_bytes.c
43 lines (37 loc) · 1.04 KB
/
010_files_bigger_n_bytes.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
// Show the file bigger than n bytes in C Program
// Created by Rajendra Kumar R Yadav
#include <stdio.h>
#include <stdlib.h>
#include <dirent.h>
#include <sys/stat.h>
int main(int argc, char **argv) {
// Get the size threshold from the user
int sizeThreshold;
printf("Enter the size threshold (in bytes): ");
scanf("%d", &sizeThreshold);
// Open the current directory
DIR *dir = opendir(".");
if (!dir) {
perror("opendir");
return 1;
}
struct dirent *entry;
while ((entry = readdir(dir)) != NULL) {
// Get file information
struct stat fileInfo;
if (stat(entry->d_name, &fileInfo) == -1) {
perror("stat");
continue;
}
// Check if the file is a regular file
if (!S_ISREG(fileInfo.st_mode)) {
continue;
}
// Check if the file size is greater than the threshold
if (fileInfo.st_size > sizeThreshold) {
printf("%s\n", entry->d_name);
}
}
closedir(dir);
return 0;
}