从boost :: filesystem访问文件夹$

时间:2017-02-27 08:40:38

标签: c++ winapi boost

我有一个名为\ Server \ video的文件夹,我可以使用boost :: filesystem解析它,但文件夹\ Server \ video $我不能。

我使用的代码是:

void find_files(const boost::filesystem::path& dir_path, std::vector<boost::filesystem::path>& results) {
    const boost::filesystem::recursive_directory_iterator end;
    boost::filesystem::recursive_directory_iterator it;
    boost::filesystem::recursive_directory_iterator current(dir_path);
    do {
        it = std::find_if(current, end,
            [](const boost::filesystem::directory_entry& e) {
            printf("%s\n", e.path().string().c_str());
            return e.path().extension() == ".avi" || e.path().extension() == ".mkv";
        });
        if (it != end) {
            results.push_back(it->path());
            current++;
        }
    } while (it != end);
}

int main(...) {

    boost::filesystem::path folder(L"\\\\Server\\video");
    boost::filesystem::path folderHidden(L"\\\\Server\\video$");

    std::vector<boost::filesystem::path> foundVideos;
    find_files(folderHidden, foundVideos);
    find_files(folder, foundVideos);
    return 0;
}

此代码适用于\ video路径,但在视频$的第一个条目上完全失败。有没有办法快速解决这个问题?

编辑: 我在e.path()。string()上添加了一个printf()来查看它失败的地方:

\\Server\video$\$RECYCLE.BIN
\\Server\video$\$RECYCLE.BIN\S-1-5-21-1894720951-1562977780-1489575960-5
00

准确的错误消息是

BOOST_FILESYSTEM_THROW(filesystem_error(
            "filesystem::recursive_directory_iterator directory error",
            ec_push_directory));
在operations.hpp

0 个答案:

没有答案