遍历文件夹中所有文件(wxWidgets)

包含头文件:

#include <wx/dir.h>
#include <wx/dirdlg.h>

  

源码:

 

    wxDirDialog dirDialog(this,wxT("Choose a folder"));

    if (dirDialog.ShowModal() != wxID_OK)
    {
        return;
    }

    size_t n = 0;
    wxArrayString files;
    wxString path = dirDialog.GetPath();
    wxDir dir(path);
    if(dir.IsOpened())
    {
        wxString filter = wxT("*.*");//文件过滤
        n = dir.GetAllFiles(path,&files,filter,wxDIR_DEFAULT);
    }
    wxString s;
    for(size_t i = 0; i<n; i++)
    {

        s<<files[i].mb_str()<<"\n";
    }
    wxMessageBox(s);

 

附:

#include <iostream>
#include <wx/dir.h>

using namespace std;

int main()
{
    wxDir dir(wxGetCwd());
    wxString file;
    bool cont = dir.GetFirst(&file, wxEmptyString,wxDIR_FILES | wxDIR_DIRS);

    while (cont)
    {
        wxPuts(file);
        cont = dir.GetNext(&file);
    }
    return 0;
}

 

你可能感兴趣的:(遍历文件夹,wxwidgets)