<pre name="code" class="cpp">char * filePath = "D:\\sample";
vector<string> files;
获取该路径下的所有文件
getFiles(filePath, files );
char str[30];
int size = files.size();
for (int i = 0;i < size;i++)
{
cout<<files[i].c_str()<<endl;
}
</pre>
- void getFiles( string path, vector<string>& files )
- {
-
- intptr_t hFile = 0;
-
- struct _finddata_t fileinfo;
- string p;
- if((hFile = _findfirst(p.assign(path).append("\\*").c_str(),&fileinfo)) != -1)
- {
- do
- {
-
-
- if((fileinfo.attrib & _A_SUBDIR))
- {
- if(strcmp(fileinfo.name,".") != 0 && strcmp(fileinfo.name,"..") != 0)
- getFiles( p.assign(path).append("\\").append(fileinfo.name), files );
- }
- else
- {
- files.push_back(p.assign(path).append("\\").append(fileinfo.name) );
- }
- }while(_findnext(hFile, &fileinfo) == 0);
- _findclose(hFile);
- }
- }