qq_16386971 2017-08-01 06:00 采纳率: 0%
浏览 1455

windows下用多线程获取某个目录下的所有文件,并将其文件信息显示出来

新手,刚学习多线程,想要实现这样一个功能,请问有推荐的书籍或技术博客吗?还有这个功能大概要怎么实现?

  • 写回答

2条回答

  • guo_jd 2017-08-01 06:40
    关注

    可以用io.h这个库

    #include
    #include
    #include

    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 {
        cout << fileInfo.name << (fileInfo.attrib&_A_SUBDIR? "[folder]":"[file]") << endl;
    } while (_findnext(hFile, &fileInfo) == 0);
    _findclose(hFile);
    return;
    

    }

    int main()
    {
    string path="G:\testdir";
    dir(path);
    return 0;
    }

    评论

报告相同问题?