如何确定另一个文件夹中存在的文件或文件夹
How to determine files or folders present within another folder?
我是新的文件阅读,我的问题是,如何确定文件/文件夹存在于另一个文件夹?
的例子:
一个文件夹,"哇"包含以下文件:
+ whoa
- hello.dll
- world.dll
- helloworld.exe
+ cplusplus //cplusplus is a folder
- c++.png
现在,我想通过c++确定"哇"的内容,我该怎么做呢?另外,我还想创建内容的树视图
在标准c++中没有可移植的方法来做到这一点。有计划在c++标准的新迭代中标准化文件系统操作。
不可移植,使用VS2012+中可用的<filesystem>
头文件。顺便说一下,这些类与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
。
相关文章:
- 如何将更多文件夹添加到c++include路径
- GetShortPathName在网络驱动器上使用中文文件夹时失败
- VS2017,C++包含目录与附加包含目录,子文件夹包含失败-但为什么
- 在 Windows 上,是否可以让 dll 在不使用 PATH 环境变量的情况下在另一个文件夹中查找依赖项?
- 如何在文档文件夹中创建目录
- "assimp/config.h"找不到,但它在文件夹中
- C++入门 5 版:类消息和文件夹
- 我可以在 Arduino 的库文件夹之外安装库吗?
- 如何按文件扩展名引用文件夹中的文件
- 在QTreeView中仅显示共享驱动器和文件夹
- 加载与引用 .NET DLL 位于同一文件夹中的引用的 .NET DLL 时"Not found"异常
- 介子复制/安装头文件到输出目录并保持文件夹结构
- vcruntime.h 从 Windows 包含文件夹中丢失?
- 在文件夹迭代上实现 RAII
- 使用 Powershell 命令将 cpp 文件的文件夹编译为 GNU 的 g++
- 使文件夹中的所有文件可供所有项目(子目录)访问
- 无法使用 CMake 从其他文件夹添加源文件
- 如何在安卓工作室中将c ++头文件从一个文件夹导入到另一个文件夹?
- 对单元测试(googletest)和项目/文件夹/文件的混淆
- 设计文件夹/文件系统