如何确定另一个文件夹中存在的文件或文件夹

How to determine files or folders present within another folder?

本文关键字:文件夹 文件 存在 何确定 另一个      更新时间:2023-10-16

我是新的文件阅读,我的问题是,如何确定文件/文件夹存在于另一个文件夹?

的例子:

一个文件夹,"哇"包含以下文件:

+ 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