We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent a675056 commit 5710dedCopy full SHA for 5710ded
C/sizeofdirectory/sizeoffolder.c
@@ -0,0 +1,27 @@
1
+#include <stdio.h>
2
+#include <dirent.h>
3
+
4
+int main(void)
5
+{
6
+ struct dirent *de; // Pointer for directory
7
+ int ctr = 0; // variable to store size
8
+ DIR *dr = opendir(".");
9
10
+ if (dr == NULL) //if directory not exist
11
+ {
12
+ printf("Can't open current directory" );
13
+ return 0;
14
+ }
15
16
+ while ((de = readdir(dr)) != NULL) //if directory exists and till the end of directory
17
18
+ FILE* fp = fopen(de->d_name, "r");
19
+ fseek(fp, 0L, SEEK_END);
20
+ ctr = ctr + ftell(fp); // calculating the size of each file in folder
21
+ fclose(fp);
22
23
24
+ printf("Directory Size : %d bytes", ctr);
25
+ closedir(dr);
26
27
+}
0 commit comments