Making a list of folders in a directory with wxWidgets

前端 未结 3 1148
情歌与酒
情歌与酒 2021-01-14 13:30

I\'m making an application with wxWidgets that has a listbox in it. I want to get the current working directory of the application, and in that listbox, list all the folders

3条回答
  •  花落未央
    2021-01-14 14:01

    For listing all the folder names in a list,

    #include "wx/dirdlg.h"
    
    wxDirDialog dialog(parent, wxT("Testing directory picker"), cwd, wxDD_NEW_DIR_BUTTON);
    if (dialog.ShowModal() == wxID_OK)
    {
         wxString path = dialog.GetPath();
         wxMessageBox(path);
    }
    

    Note : You can use path in any way you wish, here it just displays in a message box.

    But of course if you want to display folder names in your custom dialog to your user, you can use RyanWilcox solution.

    EDIT: In your code you have not created dirList (or you have posted incomplete code)

    wxArrayString MainWindow::createFolderList()
    {
        wxDir dir(wxGetCwd());
        if ( !dir.IsOpened() )
             ;//handle this error here
    
        wxString dirName = dir.GetName();
        wxArrayString dirList;
    
        dir.GetAllFiles(dirName, &dirList, wxEmptyString, wxDIR_DIRS | wxDIR_FILES);
    
        //Note that next statement is optional
        dirList.shrink();
    
        return dirList;
    }
    

    Your implementation might differ, but I have adapted this code, from my own working code.

提交回复
热议问题