-
Notifications
You must be signed in to change notification settings - Fork 20
Expand file tree
/
Copy pathstatall.c
More file actions
59 lines (48 loc) · 1.5 KB
/
statall.c
File metadata and controls
59 lines (48 loc) · 1.5 KB
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <dirent.h>
#include <string.h>
#include <sys/stat.h>
void printFilesRecursively(const char *dirname) {
DIR *dir;
struct dirent *entry;
struct stat file_stat;
if ((dir = opendir(dirname)) == NULL) {
perror("Error opening directory");
return;
}
while ((entry = readdir(dir)) != NULL) {
if (strcmp(entry->d_name, ".") == 0 || strcmp(entry->d_name, "..") == 0) {
continue;
}
char path[1024];
snprintf(path, sizeof(path), "%s/%s", dirname, entry->d_name);
if (entry->d_type == DT_DIR) {
// Recursive call for directories
printFilesRecursively(path);
} else {
volatile int i = 0;
// Use stat syscall to get file information
if (stat(path, &file_stat) == 0) {
i++;
//printf("File: %s, Size: %ld bytes\n", path, file_stat.st_size);
// You can access other file information from the 'file_stat' structure
} else {
i++;
//perror("Error getting file information");
}
}
}
closedir(dir);
}
int main() {
char currentDir[1024];
if (getcwd(currentDir, sizeof(currentDir)) == NULL) {
perror("Error getting current directory");
return EXIT_FAILURE;
}
printf("Files in the current directory:\n");
printFilesRecursively(currentDir);
return EXIT_SUCCESS;
}