c++ - 如何显示目录中的文件列表

标签 c++ c++builder vcl filelist

我的任务是显示给定目录中的文件列表。以下是我现有的代码:

FileListBox1->FileEdit = Edit1;
FilterComboBox1->FileList = FileListBox1;
DirectoryListBox1->FileList = FileListBox1;
DirectoryListBox1->DirLabel = Label1;
DriveComboBox1->DirList = DirectoryListBox1;
Button1->Default = true;

到目前为止,一切正常,但目录中只有 *.txt 文件,我想跳过这种类型的提要并立即将文件扩展名缩小到 *.txt

我已经尝试过这样的事情:

String fileType = L"*.txt";
FileListBox1->FileEdit = fileType;

还有一些其他的解决方案,但是每次都报错。

有什么想法吗?

最佳答案

您收到一个错误,因为您正试图在需要 TEdit* 的地方分配一个 String

如果您希望 TFileListBox 以可编程方式显示特定类型的文件,请去掉 TFilterComboBox 并使用 TFileListBox::Mask属性代替:

Limits which files are displayed in the file list box.

Set Mask to a regular expression to limit the list box to files that match the mask. The value of the mask is a file name that may include wildcards.

String fileType = _D("*.txt");
FileListBox1->Mask = fileType;

也就是说,您正在使用的文件 UI 组件古老,它们是在 Windows 3.1 时代设计的,不应在现代软件中使用。

查看 RTL 的 FindFirst()FindNext()函数以可编程方式枚举带有掩码过滤的文件。参见 Finding a File在 Embarcadero 的文档中了解更多详细信息。

关于c++ - 如何显示目录中的文件列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58050296/

相关文章:

c++ - 这个设置有什么问题?

c++ - 同一个词加了两次

windows - TStatusBar 控件中的模糊文本

Delphi - 使用 TApplicationEvents OnShortCut 事件检测 Alt+C 按键

listview - 检查当前是否在 Delphi VCL TListView 中显示编辑

c++ - C++ 映射中的关键比较不起作用

c++ - 为什么要调用复制构造函数?

c++ - 当用户尝试第二次运行时如何激活已经打开的应用程序?

带有 vcl 的 C++ : closing secondary form does not end process

c++ - 在 C++ Builder 2010 上包含 boost/asio.hpp 时出现编译器错误