-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLecteurRepertoire.h
48 lines (41 loc) · 1.33 KB
/
LecteurRepertoire.h
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
#ifndef LECTEURREPERTOIRE_H_INCLUDED
#define LECTEURREPERTOIRE_H_INCLUDED
#include "Lecteur.h"
#include <iostream>
#include <dirent.h>
#include <sys/types.h>
#include "LecteurFichier.h"
class LecteurRepertoire:public Lecteur{
public:
vector<string> lire(string path);
};
vector<string> LecteurRepertoire::lire(string path){
vector<string> mots,prov;
LecteurFichier lecteur_fichier;
string fileName="";
DIR *dr;
struct dirent *en;
dr = opendir(path.c_str());
if (dr) {
while ((en = readdir(dr)) != NULL) {
int i = 0;
while(true){
if(en->d_name[i]=='.'){
if((en->d_name[i+1]=='t')&&(en->d_name[i+2]=='x')&&(en->d_name[i+3]=='t')){
//in case he found a txt file
fileName=path;
fileName.append(en->d_name);
prov = lecteur_fichier.lire(fileName);
mots.insert(mots.end(),prov.begin(),prov.end());
break;
}
}
i++;
if (i>260){break;}
}
}
closedir(dr);
}
return mots;
}
#endif // LECTEURREPERTOIRE_H_INCLUDED