c++ windows下遍历某个目录下所有文件

180it 2020-10-08 PM 2621℃ 0条
#include <iostream>
#include <io.h>
#include <string>
using namespace std;
 
 
void dir(string path)
{
    long hFile = 0;
    struct _finddata_t fileInfo;
    string pathName, exdName;
 
 
    if ((hFile = _findfirst(pathName.assign(path).
        append("\\*").c_str(), &fileInfo)) == -1) {
        return;
    }
    do {
        if (fileInfo.attrib&_A_SUBDIR) {
            string fname = string(fileInfo.name);
            if (fname != ".." && fname != ".") {
                dir(path + "\\" + fname);
            } 
        } else {
            cout << path << "\\" << fileInfo.name << endl;
        }
    } while (_findnext(hFile, &fileInfo) == 0);
    _findclose(hFile);
    return;
}
 
 
int main()
{
    string path="D:\\devSoft";
    dir(path);
    return 0;
}

支付宝打赏支付宝打赏 微信打赏微信打赏

如果文章或资源对您有帮助,欢迎打赏作者。一路走来,感谢有您!

标签: none

c++ windows下遍历某个目录下所有文件