C++ 扫描文件夹下所有文件


void GetFilesFromDirectory(std::vector<std::string> &files, const char *directoryPath)
{
    struct _finddata_t fileinfo;
    long hFile = 0;
    char tmpPath[MAX_PATH] = { 0 };
    sprintf_s(tmpPath, "%s\\*", directoryPath);
    if ((hFile = _findfirst(tmpPath, &fileinfo)) == -1){ return; }
    do
    { 
        if ((fileinfo.attrib &  _A_SUBDIR))
        {
            if (strcmp(fileinfo.name, ".") != 0 && strcmp(fileinfo.name, "..") != 0)
            {
                sprintf_s(tmpPath, "%s\\%s", directoryPath, fileinfo.name);
                GetFilesFromDirectory(files, tmpPath);
            }
        }
        else
        {
            sprintf_s(tmpPath, "%s\\%s", directoryPath, fileinfo.name);
            files.push_back(tmpPath);
        }
    } while (_findnext(hFile, &fileinfo) == 0);
    _findclose(hFile);
}

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM