|
@@ -69,6 +69,59 @@ char** file_list(const char* path, int* nb) {
|
|
|
}
|
|
|
//Ajout des resultats dans la variable
|
|
|
result = malloc(sizeof (char*) * nbFile);
|
|
|
+ for (int i = scan - 1, j = 0; i >= 0; i--, j++) {
|
|
|
+ //Ne prend que les fichiers non cachés
|
|
|
+ if (namelist[i]->d_type == DT_REG && namelist[i]->d_name[0] != '.') {
|
|
|
+ length = strlen(namelist[i]->d_name) + 1;
|
|
|
+ result[j] = malloc(sizeof (char) * length);
|
|
|
+ memset(result[j], 0, length);
|
|
|
+ strncpy(result[j], namelist[i]->d_name, length - 1);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //Retourne chaine + ajout nombre de resultat
|
|
|
+ if (nb != NULL) {
|
|
|
+ *nb = nbFile;
|
|
|
+ }
|
|
|
+ return result;
|
|
|
+}
|
|
|
+
|
|
|
+char** file_list_all(const char* path, int* nb) {
|
|
|
+ struct dirent **namelist;
|
|
|
+ int scan, nbFile = 0, length;
|
|
|
+ char** result;
|
|
|
+ //Verif que le chemin est bien un dossier
|
|
|
+ if (!is_dir(path)) {
|
|
|
+ adderror("Le chemin n'est pas un dossier");
|
|
|
+ if (nb != NULL) {
|
|
|
+ *nb = ERR;
|
|
|
+ }
|
|
|
+ return NULL;
|
|
|
+ }
|
|
|
+ //Scan le repertoire
|
|
|
+ scan = scandir(path, &namelist, 0, alphasort);
|
|
|
+ if (nbFile < 0) {
|
|
|
+ addperror("Impossible de scanner les fichiers");
|
|
|
+ if (nb != NULL) {
|
|
|
+ *nb = ERR;
|
|
|
+ }
|
|
|
+ return NULL;
|
|
|
+ }
|
|
|
+ //Compte le nombre de fichier dans le dossier
|
|
|
+ int i = scan;
|
|
|
+ while (i--) {
|
|
|
+ if (namelist[i]->d_type == DT_REG) {
|
|
|
+ nbFile++;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //Si le dossier est vide
|
|
|
+ if (nbFile == 0) {
|
|
|
+ if (nb != NULL) {
|
|
|
+ *nb = 0;
|
|
|
+ }
|
|
|
+ return NULL;
|
|
|
+ }
|
|
|
+ //Ajout des resultats dans la variable
|
|
|
+ result = malloc(sizeof (char*) * nbFile);
|
|
|
for (int i = scan - 1, j = 0; i >= 0; i--, j++) {
|
|
|
//Ne prend que les fichiers non cachés
|
|
|
if (namelist[i]->d_type == DT_REG) {
|