MoreNotepad++

--------活出自己的精彩。

导航

获取文件夹下所有子文件path(_findfirst & _findnext用法)

#include <iostream>
#include <string>
#include <vector>
#include <io.h>

using namespace std;

typedef vector<string> pathVector;

pathVector getSubFilePath(const string& startPath)
{
    long  handle;
    struct _finddata_t  fileInfo;

    pathVector pathVec;

    if (startPath == "") {
        return pathVec;
    }

    handle=_findfirst((startPath + "\\*.*").c_str(), &fileInfo);

    if(handle != -1L)
    {
        while(_findnext(handle,&fileInfo) == 0)
        {
            if (string(fileInfo.name) != string("..") 
             && string(fileInfo.name) != string("."))
            {
                pathVec.push_back(startPath + "\\" + fileInfo.name);
            }
        }

        _findclose(handle);
    }

    return pathVec;
}

int main(int argc, char* argv[])
{
    pathVector vec = getSubFilePath("C:\\test");//don't need end char '\\'
    
    pathVector::iterator it = vec.begin();
    
    while (it != vec.end())
    {
        cout << (*it) << endl;
        it += 1;
    }

    return 0;
}

 

posted on 2013-06-21 13:53  MoreNotepad++  阅读(456)  评论(0)    收藏  举报