// path---文件路径
// strAry---得到的所有文件名称组成的数组
void GetAllFileNamesInFolder( string path, CStringArray& strAry)
{
struct _finddata_t fileinfo;
string strP;
vector<string> files;
if (IsWin10System())
{
//文件句柄
long long hFile = 0;
//文件信息
if ((hFile = _findfirst(strP.assign(path).append("\\*").c_str(), &fileinfo)) != -1)
{
do
{
//如果是目录,迭代之
//如果不是,加入列表
if ((fileinfo.attrib & _A_SUBDIR))
{
if (strcmp(fileinfo.name, ".") != 0 && strcmp(fileinfo.name, "..") != 0)
{
GetAllFileNamesInFolder(strP.assign(path).append("\\").append(fileinfo.name), maxLn, minLn);
}
}
else
{
files.push_back(fileinfo.name);
}
} while (_findnext(hFile, &fileinfo) == 0);
_findclose(hFile);
}
}
else
{
long hFile = 0;
//文件信息
if ((hFile = _findfirst(strP.assign(path).append("\\*").c_str(), &fileinfo)) != -1)
{
do
{
//如果是目录,迭代之
//如果不是,加入列表
if ((fileinfo.attrib & _A_SUBDIR))
{
if (strcmp(fileinfo.name, ".") != 0 && strcmp(fileinfo.name, "..") != 0)
{
GetAllFileNamesInFolder(strP.assign(path).append("\\").append(fileinfo.name), maxLn, minLn);
}
}
else
{
files.push_back(fileinfo.name);
}
} while (_findnext(hFile, &fileinfo) == 0);
_findclose(hFile);
}
}
for (int i = 0; i < files.size(); i++)
{
CString strTemp;
strTemp = files[i].c_str();
int nPos = strTemp.Find(_T('.'));
strTemp = strTemp.Mid(0, nPos);
strAry.Add(strTemp );
}
}
C++获取某个文件夹下的所有文件名称
猜你喜欢
转载自blog.csdn.net/m0_37251750/article/details/84324105
今日推荐
周排行