使用wxWidgets创建目录中的文件夹列表 [英] Making a list of folders in a directory with wxWidgets

查看:846
本文介绍了使用wxWidgets创建目录中的文件夹列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在做一个应用程序与wxWidgets其中有一个列表框。我想获取应用程序的当前工作目录,并在该列表框中列出cwd中包含特定文件的所有文件夹名称(而不是完整路径)。

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 names (not full paths) in the cwd that contain a specific file.

我已经弄清楚如何获得cwd并返回它作为一个wxString(不是我特别确定它的工作,但我会很快找到足够),但我不知道如何获得列表

I've already figured out how to get the cwd and return it as a wxString (not that I'm particularly sure it's working, but I'll find out soon enough) but I'm not sure how to get the list of folders and pass it to the listbox.

我是wxWidgets的全新版本,而且是C ++和OOP的新版本。如果你能找到一个很好的方法来解释如何做到这一点,这将是非常感激。

I'm brand new to wxWidgets, and relatively new to C++ and OOP. If you could find a good way to explain to me how to do this, it would be much appreciated.

更新:使用GetAllFiles,但现在我得到异常我运行它。这是代码。

Update: Went with using GetAllFiles, but now I get exceptions when I run it. Here is the offending code.

wxArrayString MainWindow::createFolderList()
{
    wxDir dir = wxGetCwd();

    dirAddress = dir.GetName();

    dir.GetAllFiles(dirAddress, dirList, wxEmptyString, wxDIR_DIRS | wxDIR_FILES);

    return *dirList;
}


推荐答案

=http://docs.wxwidgets.org/2.9.3/classwx_dir_traverser.html =nofollow> wxDirTraverser - 你实现一个子类,并重写一些方法,如果项目是一个档案或目录。

You could use wxDirTraverser - you implement a subclass and override some methods which will be called depending if the item is a file or directory.

您也可以使用 wxDir :: GetAllFiles ,它将返回一个wxArray(这可能更有效,在列表中显示它)。

You could also use wxDir::GetAllFiles, which will return a wxArray (which might be more convient for you, displaying it in a list).

这篇关于使用wxWidgets创建目录中的文件夹列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆