首页 > 编程语言 > 详细

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

时间:2016-11-09 12:26:18      阅读:537      评论:0      收藏:0      [点我收藏+]
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);
}

 

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

原文:http://www.cnblogs.com/tangxin-blog/p/6045871.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!