嗯嗯嗯,先上代码
#include <iostream>
#include <string>
#include <io.h>
using namespace std;
void dir(string path)
{
long hFile = 0;
struct _finddata_t fileInfo;
string pathName, exdName;
// \\* 代表要遍历所有的类型,如改成\\*.jpg表示遍历jpg类型文件
if ((hFile = _findfirst(pathName.assign(path).append("\\*").c_str(), &fileInfo)) == -1) {
return;
}
do
{
//判断文件的属性是文件夹还是文件
cout << fileInfo.name << (fileInfo.attrib&_A_SUBDIR ? "[文件夹]" : "[文件]") << endl;
} while (_findnext(hFile, &fileInfo) == 0);
_findclose(hFile);
return;
}
int main()
{
//要遍历的目录
string path = "D:\\";
dir(path);
system("pause");
return 0;
}
还是给你一张截图吧,

发表评论: