123456789101112131415161718192021222324252627282930313233343536373839404142 |
- #include <error.h>
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <sys/types.h>
- #include <dirent.h>
- int
- main (int argc, char *argv[])
- {
- DIR *dp;
- struct dirent *ep;
- if(argc==1){
- perror("Usage program base/path");
- exit(1);
- }
- dp = opendir (argv[1]);
- if (dp != NULL)
- {
- while (ep = readdir (dp)) {
- puts (ep->d_name);
- if(strcmp(ep->d_name, ".")==0 || strcmp(ep->d_name, "..")==0)
- continue;
- if(ep->d_type==DT_DIR) {
- char *subdir = malloc(strlen(argv[1])+strlen("/")+strlen(ep->d_name)+1);
- strcpy(subdir, argv[1]);
- strcat(subdir, "/");
- strcat(subdir,ep->d_name);
- char *newargv[] = {NULL, subdir};
- main(2,newargv);
- }
- }
- (void) closedir (dp);
- }
- else
- perror ("Couldn't open the directory");
- return 0;
- }
|