如何遍历目录? [英] How do I traverse into directories?

查看:33
本文介绍了如何遍历目录?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我有一个包含 5 个子文件夹的文件夹,并且我想在每个子文件夹中搜索某些文件(我的程序存在于主文件夹中).如何让我的程序在 C++ 中进出这些文件夹?

If I have a folder that has, say, 5 sub-folders, and I want to search for certain files inside each sub-folder(my program is present inside the main folder). How do I make my program traverse into and out of those folders in C++?

我需要我的程序在 Windows 平台上运行.

I need my program to run on Windows platforms.

谢谢!

推荐答案

只需使用 boost 的 recursive_directory_iterator,并过滤你想要的文件/目录.

Just use boost's recursive_directory_iterator, and filter the files/directory you want.

boost::filesystem::recursive_directory_iterator iter("your\path");
boost::filesystem::recursive_directory_iterator end;
for (; iter != end; ++iter) {
    // check for things like is_directory(iter->status()), iter->filename() ....
    // optionally, you can call iter->no_push() if you don't want to
    // enter a directory
    // see all the possibilities by reading the docs.
}

这篇关于如何遍历目录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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