/******获取目录下所有的文件*****/
#include<iostream>
#include<string>
#include <direct.h>
#include<vector>
#include "io.h"
const int MAX_PATH = 260;
enum { RETURN_ERROR = -1, RETURN_OK };
void GetFiles(const std::string& strDir, std::vector<std::string>& vecFile)
{
_finddata_t file;
long lf;
if (RETURN_ERROR == (lf = _findfirst(strDir.c_str(), &file)))
std::cout << "not found" << strDir<< std::endl;
else
{
while (RETURN_OK == _findnext(lf, &file))
{
if (RETURN_OK == strcmp(file.name, ".")
|| RETURN_OK == strcmp(file.name, ".."))
continue;
if (file.attrib&_A_SUBDIR)
{
std::string strTmpDir(strDir.substr(0, strDir.length() - 1) + file.name + "\\*");
GetFiles(strTmpDir, vecFile);
}
else
vecFile.push_back(file.name);
}
}
_findclose(lf);
}
int main()
{
char szPath[MAX_PATH] = { 0 };
_getcwd(szPath, MAX_PATH);
strncat_s(szPath, "\\*", MAX_PATH);
std::vector<std::string> vecFile;
GetFiles(szPath, vecFile);
for (auto&it : vecFile)
std::cout << it << std::endl;
system("pause");
return 0;
}
#include<iostream>
#include<string>
#include <direct.h>
#include<vector>
#include "io.h"
const int MAX_PATH = 260;
enum { RETURN_ERROR = -1, RETURN_OK };
void GetFiles(const std::string& strDir, std::vector<std::string>& vecFile)
{
_finddata_t file;
long lf;
if (RETURN_ERROR == (lf = _findfirst(strDir.c_str(), &file)))
std::cout << "not found" << strDir<< std::endl;
else
{
while (RETURN_OK == _findnext(lf, &file))
{
if (RETURN_OK == strcmp(file.name, ".")
|| RETURN_OK == strcmp(file.name, ".."))
continue;
if (file.attrib&_A_SUBDIR)
{
std::string strTmpDir(strDir.substr(0, strDir.length() - 1) + file.name + "\\*");
GetFiles(strTmpDir, vecFile);
}
else
vecFile.push_back(file.name);
}
}
_findclose(lf);
}
int main()
{
char szPath[MAX_PATH] = { 0 };
_getcwd(szPath, MAX_PATH);
strncat_s(szPath, "\\*", MAX_PATH);
std::vector<std::string> vecFile;
GetFiles(szPath, vecFile);
for (auto&it : vecFile)
std::cout << it << std::endl;
system("pause");
return 0;
}