如何填充C ++中的列表框与目录中的所有文件夹 [英] How to populate a Listbox in C++ with all folders in a directory

查看:138
本文介绍了如何填充C ++中的列表框与目录中的所有文件夹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道如何在列表框中的目录中列出所有文件夹。我使用Visual C ++。

I would like to know how to list all folder in a directory in a listbox. I am using Visual C++.

推荐答案

C ++是一种不指定任何标准类或函数来实现图形界面的语言。它也不提供从操作系统获取文件和目录的列表的标准方法!事实上...很长一段时间里,甚至没有一个标准的字符串类,每个项目选择不同的不兼容的字符串。

C++ is a language that does not specify any standard classes or functions for implementing graphical interfaces. It also doesn't provide a standard way of getting lists of files and directories from the operating system!!! In fact...for a long time there wasn't even a standard for string classes, and every project chose different incompatible strings.

注意:现在有一个标准的 string 类,碎片遗留继续:

Note: Even though there's now a standard string class, the fragmented legacy continues: Why is there a different string class in every C++ platform out there?

因此,当您标记某个C ++或使用该术语时,它仅指语言引擎本身。尽管这可能听起来有限,其中一个强大的优势是,这个引擎是(相对)强大的,你不需要构建东西,使它们高效或有一个深层的编码接口。该语言的用户几乎拥有创建酷语言功能的能力,就像他们能够修改编译器本身一样。

So when you tag something "C++" or use that term, it refers only the language engine itself. As limited as that may sound, one of the great strengths is that this engine is so (relatively) powerful that you don't need to build things in to make them efficient or have a deep coding interface. Users of the language have nearly as much power to create cool language features as if they were able to modify the compiler itself.

这是一个陡峭的山坡,为初学者攀登,虽然。

It's a steep hill to climb for beginners, though.

所有这一切都意味着一个问题,如如何填充C ++中的列表框与所有文件夹一个目录?是非常开放的。它取决于您选择用于GUI的工具包,以及与文件系统通信。一些工具包是大,并提供综合类来涵盖这两个领域:

All of that means that a question like "How to populate a Listbox in C++ with all folders in a directory?" is very open-ended. It depends on what toolkits you're choosing to use for the GUI, and for talking to the filesystem. Some toolkits are "big" and offer comprehensive classes to cover both areas:

http://doc.qt.nokia.com/latest/qdir.html#navigation-and-directory-operations

http://doc.qt。 nokia.com/latest/itemviews-dirview.html

其他图书馆更为狭窄,只提供一个功能。例如,boost是一组几乎标准库,尚未加入C ++规范。有一种方法用C ++使用 boost :: filesystem 枚举文件和目录。这对初学者来说是令人生畏的:

Other libraries are more narrow and provide just one function or another. For instance, "boost" is a set of almost standard libraries that haven't yet made it into the C++ spec. There's a way to enumerate files and directories with C++ using boost::filesystem. It's daunting for beginners, though:

http://www.boost.org/doc/libs/1_48_0/libs/filesystem/v3/doc/tutorial.html

如果您愿意将自己链接到特定的操作系统或实现 - 例如调用只能在Windows上使用的功能,或者仅在Linux下使用GTK,或仅在MacOS上使用 - 有权访问平台+工具包提供什么。但是因为C ++是平台无关的,一旦你跨越这一行,你不再在只是C ++编程,你的问题和标签在StackOverflow需要澄清你做了什么选择。

If you're willing to chain yourself to a particular operating system or implementation--such as make calls to functions only available on Windows, or only on Linux under GTK, or only on MacOS--then you have access to what that platform+toolkit provides. But because C++ is platform-independent, once you cross that line you're no longer programming in "just C++" and your question and tags on StackOverflow need to clarify what choices you've made.

你对SO的其他问题都是关于Visual Studio和VB的,所以我假设你使用Windows。

Your other questions on SO are about Visual Studio and VB so I'm assuming you're using Windows.

您应该注意的一个相关主题是常见对话框。这些是提供的便利,以便每个人不必编写自己的文件 - >打开逻辑,或颜色选择器或搜索对话框。 Microsoft已在Windows上定义了其中的一些:

One related topic you should be aware of are "common dialogs". These are conveniences provided so that everyone doesn't have to write their own "File->Open" logic, or color picker, or search dialog. Microsoft has some of them defined on Windows:

http://msdn.microsoft.com/en-us/library/windows/desktop/ms646960(v = VS.85).aspx

因此,如果选择文件,文件,目录或目录是一些代码的简单目的...那些保存你的麻烦。 Qt有类似的东西:

So if picking a file, files, directory, or directories is the simple purpose of some code...those save you the trouble. Qt has similar things:

http://doc.qt.nokia.com/stable/qfiledialog.html#details

您可以编辑您的问题,以便更多地了解您的目的。如果你对C ++感兴趣,只是想潜水,并有一套有效的功能,将在Windows,Mac或Linux上工作...考虑尝试Qt Creator:

You can edit your question to add more about your purposes. If you are curious about C++ and just want to dive in and have a well-documented set of functionality that will work on Windows, Mac, or Linux... consider trying Qt Creator:

http://www.qt.io/ide/

Microsoft已经将他们的策略绑定在.NET和C#上,所以至少现在如果你使用Qt,你将更坚定地成为一个C ++ GUI程序员。

Microsoft has really hinged their strategy on .NET and C#, so at least right now you'll stand on firmer ground as a C++ GUI programmer if you go with Qt.

这篇关于如何填充C ++中的列表框与目录中的所有文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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