Salut, j'ai un soucis avec la fonction readdir.
Celle-ci me renvoie trop de fichiers dont certains qui n'existent pas et certains sont listés deux fois.
J'avais supprimé auparavant des fichiers dans le dossier de l'application et j'ai recrée plusieurs fois le dossier .
Je n'ai que 4 fichiers dans le dossier : (test.hpp, test.cpp, main.cpp, test.out)
Pour les lister, j'effectue ceci, en fait, je veux récupérer les noms des headers et des fichiers source pour les ouvrir.
Code cpp : Sélectionner tout - Visualiser dans une fenêtre à part
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 void ODFAEGCreator::showHeadersFiles(Label* label) { if (label->getChildren().size() == 0) { FontManager<Fonts>& fm = cache.resourceManager<Font, Fonts>("FontManager"); std::vector<std::string> files; std::string cpath = getCurrentPath(); findFiles("hpp", files, cpath+"/"+appliname); unsigned int y = label->getPosition().y + 10; unsigned int toMove = 0; for (unsigned int i = 0; i < files.size(); i++) { Label* lab = new Label(getRenderWindow(), Vec3f(0, y+toMove, 0), Vec3f(200, 10, 0),fm.getResourceByAlias(Fonts::Serif), files[i]); lab->setParent(lab); label->addChild(lab); toMove += 10; } std::vector<LightComponent*> children = label->getParent()->getChildren(); for (unsigned int i = 0; i < children.size(); i++) { if (children[i]->getPosition().y > label->getPosition().y) { children[i]->move(Vec3f(0, toMove, 0)); std::vector<LightComponent*> schildren = children[i]->getChildren(); for (unsigned int j = 0; j < schildren.size(); j++) { schildren[j]->move(Vec3f(0, toMove, 0)); } } } } else { unsigned int y = label->getPosition().y + 10; std::vector<LightComponent*> children = label->getParent()->getChildren(); int toMove = -children.size() * 10; for (unsigned int i = 0; i < children.size(); i++) { if (children[i]->getPosition().y > y) { children[i]->move(Vec3f(0, toMove, 0)); std::vector<LightComponent*> schildren = children[i]->getChildren(); for (unsigned int j = 0; j < schildren.size(); j++) { schildren[j]->move(Vec3f(0, toMove, 0)); } } } label->removeAll(); } }
Voici la fonction qui va rechercher les chemins des fichiers :
Code cpp : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 void findFiles (std::string keyword, std::vector<std::string>& files, std::string startDir) { if (DIR* current = opendir(startDir.c_str())) { dirent* ent; while ((ent = readdir(current)) != NULL) { if (strcmp(ent->d_name, ".") && strcmp(ent->d_name, "..")) { std::string path(ent->d_name); if (ent->d_type == DT_DIR) { findFiles(keyword, files, path); } else if (path.find(keyword) != std::string::npos) { files.push_back(path); } } } closedir(current); } }
Dans les fichiers listé j'ai :
Hors que le fichier .hpp n'existe pas.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3 .hpp test.hpp
Dans les fichiers sources j'ai :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6 main.cpp application.cpp .cpp (n'existe pas) main.cpp (déjà listé) test.cpp
Partager