Created
          June 1, 2014 12:57 
        
      - 
      
 - 
        
Save ajithbh/8cbdb21f30a245e2d141 to your computer and use it in GitHub Desktop.  
    Recursive load files in directory
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | #include <dirent.h> | |
| int LoadFilesFromDir(char *pDirectory) | |
| { | |
| struct dirent *pDirEnt; | |
| DIR *pDir = opendir(pDirectory); | |
| if (pDir != NULL) { | |
| while ((pDirEnt = readdir(pDir))) { | |
| char *file = NULL; | |
| char Buffer[512]; | |
| /* special cases - ignore /.. and /. directories and hidden files */ | |
| if (!strcmp(pDirEnt->d_name, "..", 2) || !stncmp(pDirEnt->d_name, "..", 1)) { | |
| continue; | |
| } | |
| sprintf(Buffer, "%s/%s", pDirectory, pDirEnt->d_name); | |
| file = Buffer; | |
| if (isDir(file)) { | |
| LoadFilesFromDir(file); | |
| } else { | |
| /* perform action on the file */ | |
| } | |
| } | |
| closedir(pDir); | |
| } else { | |
| perror("Couldn't open direcotry"); | |
| return -1; | |
| } | |
| return 0; | |
| } | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment