我是文件阅读的新手,我的问题是,如何确定另一个文件夹中存在的文件/文件夹?
例子:
文件夹“ whoa”包含以下文件:
+ whoa
- hello.dll
- world.dll
- helloworld.exe
+ cplusplus //cplusplus is a folder
- c++.png
现在,我想通过c ++确定“ whoa”的内容,我该怎么做?另外,我也想创建内容的树状视图。
在标准C ++中,没有可移植的方法可以做到这一点。有计划在C ++标准的新版本中标准化文件系统操作。
不可移植,使用<filesystem>
VS2012 +中提供的标头。顺便说一句,这些类与的类非常相似boost::filesystem
。
std::vector<string> filePaths;
path folderPath = "whoa";
if (is_directory(folderPath))
{
// This recursively traverses the folder structure.
// Use directory_iterator if just want to traverse the current folder.
recursive_directory_iterator endit;
recursive_directory_iterator it(folderPath);
for (; it != endit; ++it)
{
string filePath = it->path().string();
filePaths.push_back(filePath);
}
}
如果您想要可移植性,请查看boost::filesystem
。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句