src/find.c
//lists all the file into the correct structure and, if requested, opens them recursively
lists all the file into the correct structure and, if requested, opens them recursively
lists all the file into the correct structure and if requested opens them recursively
void listFilesRecursively(char *basePath, const char *recursive, const int a, const char *exclude){
    struct dirent *dp;
    DIR *dir;
    if(a == 0){ 
        listHead = createFList(listHead, listTail, basePath, getDirectory(basePath));
    }else{ 
        char *path = malloc(sizeof(char)*1000); 
        dir = opendir(basePath); 
        if (!dir) return;
        while ((dp = readdir(dir)) != NULL){ 
            if (strcmp(dp->d_name, ".") != 0 && strcmp(dp->d_name, "..") != 0){
                strcpy(path, basePath);
                strcat(path, "/"); 
                strcat(path, dp->d_name); 
                if(isRegularFile(path)){
                    if(exclude != NULL){
                        if(strcmp(exclude, getFilenameExt(path)) == 0){                           
                            continue;
                        }
                    }
                    listHead = createFList(listHead, listTail, strdup(path), strdup(basePath));
                }
                if(recursive == NULL){ 
                    continue;
                } 
                if(strcmp(recursive, "r") == 0){  
                    listFilesRecursively(path, "r", 1, exclude);
                }
            }
        }
        closedir(dir);
    }
}
void listFilesRecursively ( char * basePath , const char * recursive , const int a , const char * exclude ) { struct dirent * dp ; DIR * dir ; if ( a == 0 ) { listHead = createFList ( listHead , listTail , basePath , getDirectory ( basePath ) ) ; } else { char * path = malloc ( sizeof ( char ) * 1000 ) ; dir = opendir ( basePath ) ; if ( ! dir ) return ; while ( ( dp = readdir ( dir ) ) != NULL ) { if ( strcmp ( dp -> d_name , " " ) != 0 && strcmp ( dp -> d_name , " " ) != 0 ) { strcpy ( path , basePath ) ; strcat ( path , " " ) ; strcat ( path , dp -> d_name ) ; if ( isRegularFile ( path ) ) { if ( exclude != NULL ) { if ( strcmp ( exclude , getFilenameExt ( path ) ) == 0 ) { continue ; } } listHead = createFList ( listHead , listTail , strdup ( path ) , strdup ( basePath ) ) ; } if ( recursive == NULL ) { continue ; } if ( strcmp ( recursive , " " ) == 0 ) { listFilesRecursively ( path , " " , 1 , exclude ) ; } } } closedir ( dir ) ; } }
lists all the file into the correct structure and, if requested, opens them recursively
lists all the file into the correct structure and if requested opens them recursively
//which means is a file //if it's a directory //will store the path //open the directory //we traverse the directory // Construct new path from our base path //adding the file name to the path //in case we don't need to read recursively //if we passed a "r" to the function, the program start read recursively all the subdirectories