Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <sys/types.h>
- #include <sys/dir.h>
- #include<stdio.h>
- #include<sys/stat.h>
- #include<fcntl.h>
- #include<unistd.h>
- #include<stdlib.h>
- #include<ctype.h>
- #include<string.h>
- #define MAX_CHARS 200
- int CharsRead,Tmp;
- struct direct *DirEntryPtr;
- DIR *DirPtr;
- struct stat Stat;
- char Path[MAX_CHARS];
- void printInFile(char *buff, char *file)
- {
- int fis = open(file,O_CREAT | O_APPEND | O_WRONLY);
- if(fis == -1)
- {
- printf("Error on file open!\n");
- exit(1);
- }
- write(fis, buff, strlen(buff));
- close(fis);
- }
- int function(const char* dirName)
- {
- int size = 0;
- DirPtr = opendir(dirName);
- char buff[100];
- char buff2[100];
- while ((DirEntryPtr = readdir(DirPtr)) != NULL)
- {
- if ((strcmp(DirEntryPtr->d_name,".") != 0) || (strcmp(DirEntryPtr->d_name,"..") != 0))
- {
- printf("%s \n",DirEntryPtr->d_name);
- Path[0] = 0;
- strcat(Path,dirName);
- strcat(Path,"/");
- strcat(Path,DirEntryPtr->d_name);
- Tmp = stat(Path,&Stat);
- int n;
- int m;
- if (S_ISDIR(Stat.st_mode))
- {
- n = sprintf(buff, "Dimensiunea directorului : %lld bytes\n",(long long) Stat.st_size);
- printInFile(buff, "output.txt");
- }
- if(S_ISREG(Stat.st_mode))
- {
- m = sprintf(buff2, "Dimensiunea fisierului : %lld bytes\n",(long long) Stat.st_size);
- printInFile(buff2, "output.txt");
- }
- }
- }
- return size;
- }
- int main(int argc, char *argv[])
- {
- function(argv[1]);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement