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 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216
|
#include <iostream>
#include <vector>
#include <string>
#include <dirent.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <time.h>
#include <stdio.h>
#include <stdlib.h>
using std::string;
/*
_______________________________
/______________________________/|
|| Coder par panthere noire ||
|| liscence GPL v3 ||
|/_____________________________|/
Ce code est destiner a lister.
Les fichier et les répertoire sous linux.
Avec leur atribbus aux complet.
*/
// prototype
//permet de filtrer les donnée fourni en paramettre nottament
//et initialise la majoriter des variables
void init_source_prepare(std::vector<string> &french_only, std::string &source_path_filtre_anti_slach);
//Recherche des fichier
void search_find_file_dir(std::string *,std::vector<string> &done_rep_only,
std::vector<string> &done_rep_and_file, std::vector<string> &done_file_only);
//Recherche les informations sur les fichier chmod,chown etc
void info_stat(string,std::vector<string> &french_only);
//Contien un tableau du language français,pour une traduction ulterieur
void langue_fr(std::vector<string> &french_only);
//gestion de l'affichage
void affichage(std::vector<string> &french_only,std::vector<string> &done_rep_only, std::vector<string> &done_rep_and_file, std::vector<string> &done_file_only);
//code
void langue_fr (std::vector<string> &french_only)
{
/*
on commente les lignes
de manière a éventuelement
les charger depuis un fichier
Et pour changer facilment la langue (traduction en anglais par exemple)
*/
french_only.push_back("Démmarage de la recherche des répertoires"); //1
french_only.push_back("Type de fichier : périphérique bloc"); //2
french_only.push_back("Type de fichier : périphérique caractère"); //3
french_only.push_back("Type de fichier : répertoire"); //4
french_only.push_back("Type de fichier : FIFO/tube"); //5
french_only.push_back("Type de fichier : lien symbolique"); //6
french_only.push_back("Type de fichier : fichier ordinaire"); //7
french_only.push_back("Type de fichier : socket"); //8
french_only.push_back("Type de fichier : inconnu ?"); //9
french_only.push_back("Numéro dinud : "); //10
french_only.push_back("Mode : "); //11
french_only.push_back("(Octal)"); //12
french_only.push_back("Nombre de liens : "); //13
french_only.push_back("Propriétaires : UID="); //14
french_only.push_back(" GID="); //15
french_only.push_back("Taille de bloc dE/S : "); //16
french_only.push_back(" octets"); //17
french_only.push_back("Taille du fichier : "); //18
french_only.push_back("Blocs alloués : "); //19
french_only.push_back("Dernier changement détat "); //20
french_only.push_back("Dernier accès au fichier "); //21
french_only.push_back("Dernière modification du fichier "); //22
french_only.push_back("Opération terminée "); //23
}
void init_source_prepare(std::vector<string> &french_only, std::string &source_path_filtre_anti_slach)
{
std::vector<std::string> done_rep_only;
std::vector<string> done_rep_and_file;
std::vector<string> done_file_only;
std:string path_ok;
if (source_path_filtre_anti_slach == "")
{
return;
}
int lp = source_path_filtre_anti_slach.length();
if (source_path_filtre_anti_slach.substr((lp- 1), lp) != "/")
{
path_ok = source_path_filtre_anti_slach += "/";
}
search_find_file_dir(&path_ok,done_rep_only,done_rep_and_file,done_file_only);
//affichage(french_only,done_rep_only,done_rep_and_file, done_file_only);
}
void search_find_file_dir(std::string *dir_source, std::vector<string> &done_rep_only,
std::vector<string> &done_rep_and_file,std::vector<string> &done_file_only)
{
//variable
DIR *pointeur_flux_dir;
struct dirent *pointeur_flux_file;
std:string read_flux_file;
std::string N="";
std::string NB="";
//code
pointeur_flux_dir = opendir((*dir_source).c_str());
if (pointeur_flux_dir == NULL)
{
//std::cout << "POINTEUR NULL ------------------------------EXITED :" << std::endl;
return;
}
while ((pointeur_flux_file = readdir(pointeur_flux_dir)) != NULL)
{
read_flux_file = pointeur_flux_file->d_name;
if ( read_flux_file == "." || read_flux_file == "..")
{
continue;
}
if (pointeur_flux_file->d_type == DT_DIR) {
//ajout
NB=*dir_source;
//std::cout << "DEBUG2 :" << NB << std::endl;
int lp = NB.length();
if (NB.substr((lp- 1), lp) != "/")
{
N=*dir_source + "/" + pointeur_flux_file->d_name;
}
else
{
N=*dir_source + pointeur_flux_file->d_name;
}
//N=*dir_source + "/" + pointeur_flux_file->d_name;
done_rep_only.push_back(N);
std::cout << "DB---->|: " << N << std::endl;
search_find_file_dir(&N,done_rep_only,done_rep_and_file,done_file_only);
}
else
{
done_rep_and_file.push_back(*dir_source + "/" + pointeur_flux_file->d_name);
done_file_only.push_back(pointeur_flux_file->d_name);
}
}
}
void info_stat (std::string file_or_rep, std::vector<string> &french_only)
{
struct stat sb;
std:string Buff;
if (stat(file_or_rep.c_str(), &sb) == -1)
{
perror("stat");
}
else
{
switch (sb.st_mode & S_IFMT)
{
case S_IFBLK: std::cout << french_only[1] << std::endl;break;
case S_IFCHR: std::cout << french_only[2] << std::endl;break;
case S_IFDIR: std::cout << french_only[3] << std::endl;break;
case S_IFIFO: std::cout << french_only[4] << std::endl;break;
case S_IFLNK: std::cout << french_only[5] << std::endl;break;
case S_IFREG: std::cout << french_only[6] << std::endl;break;
case S_IFSOCK: std::cout << french_only[7] << std::endl;break;
default: std::cout << french_only[8] << std::endl;break;
}
std::cout << french_only[9] << ((long) sb.st_ino) << std::endl;
std::cout << french_only[10] << ((unsigned long) sb.st_mode)<< french_only[11]<< std::endl;
std::cout << french_only[12] << ((long) sb.st_nlink) << std::endl;
std::cout << french_only[13] << ((long) sb.st_uid) << french_only[14] << ((long) sb.st_gid)<< std::endl;
std::cout << french_only[15] <<((long) sb.st_blksize) << french_only[16] << std::endl;
std::cout << french_only[17] <<((long long) sb.st_size)<< french_only[16] << std::endl;
std::cout << french_only[18] <<((long long) sb.st_blocks) << std::endl;
std::cout << french_only[19] <<(ctime(&sb.st_ctime)) << std::endl;
std::cout << french_only[20] <<(ctime(&sb.st_atime)) << std::endl;
std::cout << french_only[21] <<(ctime(&sb.st_mtime)) << std::endl;
}
}
void affichage(std::vector<string> &french_only, std::vector<string> &done_rep_only, std::vector<string> &done_rep_and_file, std::vector<string> &done_file_only)
{
for (long i = 0; i < done_rep_only.size(); ++i )
{
std::cout << done_rep_only[i] << std::endl;
}
info_stat(done_rep_only[0],french_only);
}
int main()
{
//chargement de la langue initialisation du tableaux
std::vector<string> french_only;
langue_fr(french_only);
//variable
std::string source_scan;
//répertoire a scanner
source_scan = "/home";
//code
std::cout << french_only[0] << std::endl;
init_source_prepare(french_only,source_scan);
std::cout << french_only[22] << std::endl;
return 0;
} |
Partager