1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91
|
#include <iostream>
#include <vector>
#include <string>
#include <dirent.h>
#include <sys/stat.h>
using std::string;
/*
_______________________________
/______________________________/|
|| Coder par panthere noire ||
|| liscence GPL v3 ||
|/_____________________________|/
Ce code est destiner a lister le plus rapidement possible.
Les fichier et les répertoire sous linux.
Avec leur atribbus aux complet.
*/
void Full_Search(std::vector<string> &search_full_path,
std::vector<string> &search_rep_name,
std::vector<string> &search_file_name,
std::vector<string> &stat_info,long &number_element); //Prototype Full_Search
void Full_Search(std::vector<string> &search_full_path,
std::vector<string> &search_rep_name,
std::vector<string> &search_file_name,
std::vector<string> &stat_info, long &number_element)
{
if (search_full_path[ number_element ] != "")
{
int cmb = search_full_path[ number_element ].length();
if (search_full_path[ number_element ].substr((cmb- 1), cmb) != "/")
{
search_full_path[ number_element ] += "/";
}
/* if (search_full_path[ number_element ] != search_full_path[ 0 ])
{
search_full_path[ number_element ] = search_full_path[ 0 ] += search_full_path[ number_element ];
}
*/
DIR *InitialRep = opendir(search_full_path[ number_element ].c_str());
if (InitialRep != NULL)
{
//std::cout << search_full_path[ number_element ] << std::endl;
struct dirent *SRep;
while ((SRep = readdir(InitialRep)) != NULL) //tant que le répertoire contient des fichiers
{
string FileFound = SRep->d_name; //definir le chemin d'acces complet
string PathFound = search_full_path[ number_element ] + FileFound; // chemin complet
std::cout << "DEBUG 1: " << FileFound << std::endl;
if (FileFound != "." && FileFound != "..")
{
search_full_path[ 0 ] = PathFound + "/"; //Le bug ce situe peut être ici
std::cout << "DEBUG 8: " << search_full_path[ number_element ] << "nombre d'élément " << number_element << std::endl;
if (opendir(PathFound.c_str()) != NULL)
{
std::cout << "DEBUG 1: " << FileFound << std::endl; //affichage
//search_full_path.push_back(FileFound);
search_full_path.push_back(search_full_path[ number_element ]);// ajout des nouvelle entrée
++number_element;
std::cout << "nombre d'élément " << number_element << std::endl;
Full_Search(search_full_path, search_rep_name,
search_file_name, stat_info,number_element); //apelle recusif pour les sous répertoires bug ?
}
}
} //while
}
closedir(InitialRep); //fermer le repertoire courant
}
} //function Full_Search
int main()
{
//variable
std::vector<std::string> search_full_path; // chemin complet,note il serait probablement utile de fournire plusieur chemin a la fois.
std::vector<std::string> search_rep_name; // repertoir seulement
std::vector<std::string> search_file_name; // fichier seulement
std::vector<std::string> stat_info; // information global sur le répertoir ou le dossier
long number_element;
//code
search_full_path.push_back("/home");
number_element=0;
Full_Search(search_full_path, search_rep_name, search_file_name, stat_info,number_element);
//std::cout << search_full_path[ 1 ]<< std::endl;
std::cout << "nombre d'élément " << number_element << std::endl;
return 0;
} // main |
Partager