不写废话,直接代码
window
#include<vector>
#include<io.h>
void getFiles(string path, vector<string>& files)
{
//文件句柄,此处intptr_t是用于跨平台运行,
//例如原本在32位电脑所用文件地址编码long即可,
//但在64位电脑中运行则需要long long而我们使用intptr_t即可解决这一问题
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);
}
}
<