Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <sys/types.h>
- #include <sys/stat.h>
- #include <fcntl.h>
- #include <unistd.h>
- #include <dirent.h>
- #include <stdlib.h>
- int main(int argc , char **argv){
- DIR *dir;
- struct dirent *entree;
- struct stat info;
- int descOutput;
- int descCurrent;
- int nbrOc;
- char buffer[1024];
- if (argc != 2) {
- printf("argg sdq");
- exit(-1);
- }
- if (lstat(argv[1], &info) == -1) {
- printf("error stat");
- exit(-1);
- }
- if(!S_ISDIR(info.st_mode) ){
- printf("n'est pa dossier \n");
- }
- if(chdir(argv[1]) !=0){
- printf("erreur chdir \n");
- }
- dir=opendir(".");
- descOutput=open("/tmp/filereg",O_WRONLY|O_CREAT|O_TRUNC |O_APPEND,0666);
- while(entree=readdir(dir)){
- stat(entree->d_name, &info);
- if(S_ISREG(info.st_mode) ){
- printf("%s \n",entree->d_name);
- descCurrent=open(entree->d_name,O_RDONLY);
- while(nbrOc=read(descCurrent, buffer,1024)){
- printf("%d nbr caracere lu\n",nbrOc );
- write(descOutput,buffer,nbrOc);
- }
- close(descCurrent);
- }
- }
- close(descOutput);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement