Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <unistd.h>
- #include <iostream>
- #include <string.h>
- #include <dirent.h>
- #include <sys/stat.h>
- int main(int argc, char *argv[])
- {
- char PathName [256] = "/home/ubermarginal/proces";
- pid_t id;
- DIR *dir;
- dirent *dirName;
- struct stat bufStat;
- dir = opendir(PathName);
- char PathNamebuf[256]="";
- while ( (dirName = readdir(dir) )!=NULL )
- {
- strcpy(PathNamebuf,PathName);
- strcat(PathNamebuf,"/");
- strcat(PathNamebuf,dirName->d_name);
- int statError = stat(PathNamebuf,&bufStat);
- if (statError == 0)
- {
- if ( (S_ISDIR(bufStat.st_mode)!=0) && ((strcmp(dirName->d_name,".") ) &&(strcmp(dirName->d_name,"..") ) ) )
- {
- //std::cout << PathNamebuf << std::endl;
- id = fork();
- switch (id) {
- case -1:
- std::cout << "Error" << std::endl;
- break;
- case 0:
- closedir(dir);
- strcpy(PathName,PathNamebuf);
- std::cout << PathName << std::endl;
- dir = opendir(PathNamebuf);
- break;
- default:
- break;
- }
- }
- }
- }
- closedir(dir);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement