Advertisement
viveka0690

SUB DIRECTORY SEARCH PROGRAMS

Sep 21st, 2014
194
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.79 KB | None | 0 0
  1. #include<dirent.h>
  2. #include<stdio.h>
  3. #include<sys/types.h>
  4. #include<sys/stat.h>
  5. int main()
  6. {
  7.         DIR *d;
  8.         struct dirent *dir;
  9.         struct stat statbuf;
  10.         //d=opendir("../../../../");
  11.         d=opendir(".");
  12.         if(d)
  13.         {
  14.         while((dir=readdir(d))!=NULL)
  15.         {
  16.         //if(statbuf.st_mode & S_IFDIR !=0)
  17.         if(S_ISDIR(statbuf.st_mode))   /*Checking condition */
  18.         {
  19.         printf("Vivek\n");
  20.         printf("%s\n",dir->d_name);
  21.         }
  22.         if(S_ISREG(statbuf.st_mode))
  23.         {
  24.         printf("%s\n",dir->d_name);
  25.         }
  26.         printf("%s\n",dir->d_name);  /*simple all files displays */
  27.         }
  28.         closedir(d);
  29.         }
  30.         return 0;
  31. }
  32. @C -Programs to find a list of subdirectories in current directory @
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement