Skip to content

Commit 4fafccd

Browse files
committed
Replace dirent with std::filesystem
1 parent 79f31d6 commit 4fafccd

File tree

3 files changed

+51
-1254
lines changed

3 files changed

+51
-1254
lines changed

source/create_dialog_derived.cpp

Lines changed: 15 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,7 @@
55
//
66

77
#include "interface_derived.hpp"
8-
#if defined _WIN32
9-
#include "dirent.h"
10-
#else
11-
#include <dirent.h>
12-
#endif
8+
#include <filesystem>
139
#include <wx/msgdlg.h>
1410
#include <fmt/format.h>
1511
#include <wx/choicdlg.h>
@@ -173,27 +169,20 @@ void CreateProjectDialogD::loadTemplates(const editor& e){
173169

174170
//open the folder
175171
auto templatesFolder = e.path /e.name / templatesDir;
176-
DIR* dir = opendir(templatesFolder.string().c_str());
177-
struct dirent *entry = readdir(dir);
178-
//loop over the contents
179-
while (entry != NULL)
180-
{
181-
//does the file start with the correct prefix?
182-
if (string(entry->d_name).rfind(templatePrefix,0)==0){
183-
//add it to the UI
184-
wxListItem i;
185-
i.SetId(0);
186-
string label = entry->d_name;
187-
i.SetText(label.substr(templatePrefix.length()+1));
188-
189-
templateCtrl->InsertItem(i);
190-
}
191-
//advance to next item in folder
192-
entry = readdir(dir);
193-
}
194-
//free resources
195-
closedir(dir);
196-
free(entry);
172+
173+
for(const auto& entry : std::filesystem::directory_iterator{templatesFolder}){
174+
//does the file start with the correct prefix?
175+
auto path = entry.path();
176+
if (path.filename().string().rfind(templatePrefix,0)==0){
177+
//add it to the UI
178+
wxListItem i;
179+
i.SetId(0);
180+
string label = path.filename();
181+
i.SetText(label.substr(templatePrefix.length()+1));
182+
183+
templateCtrl->InsertItem(i);
184+
}
185+
}
197186
}
198187

199188
void CreateProjectDialogD::OnChoiceChanged(wxCommandEvent& event){

0 commit comments

Comments
 (0)