void GetAllFiles(char* lpPath, std::vector<wstring> &fileList)
{
char szFind[MAX_PATH];
string strRootPath = lpPath; //根路径
WIN32_FIND_DATA FindFileData;
memset(szFind, 0, MAX_PATH);
strcpy(szFind, lpPath);
strcat(szFind, "\\*.*");
strRootPath.append("\\");
wstring wstrRPath = _T(""); //根路径
wstrRPath = string_to_wstring(szFind);
HANDLE hFind = FindFirstFile(wstrRPath.c_str(), &FindFileData);
if (INVALID_HANDLE_VALUE == hFind)
return;
while (true)
{
if (FindFileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
{
//如果是目录
if (FindFileData.cFileName[0] != '.')
{
string strFile = "";
char szFile[MAX_PATH];
memset(szFile, 0, MAX_PATH);
strFile = lpPath;
strFile.append("\\");
wstrRPath = FindFileData.cFileName;
strFile.append(wstring_to_string(wstrRPath));
strcat(szFile, strFile.c_str());
GetAllFiles(szFile, fileList);
}
}
else
{
//如果是文件,加入到数组
wstrRPath = FindFileData.cFileName; //文件名
wstring wstrTemp = string_to_wstring(strRootPath); //根路径
wstrTemp += wstrRPath; //组合文件路径
fileList.push_back(wstrTemp);
}
if (!FindNextFile(hFind, &FindFileData)) break;
}
FindClose(hFind);
}
{
char szFind[MAX_PATH];
string strRootPath = lpPath; //根路径
WIN32_FIND_DATA FindFileData;
memset(szFind, 0, MAX_PATH);
strcpy(szFind, lpPath);
strcat(szFind, "\\*.*");
strRootPath.append("\\");
wstring wstrRPath = _T(""); //根路径
wstrRPath = string_to_wstring(szFind);
HANDLE hFind = FindFirstFile(wstrRPath.c_str(), &FindFileData);
if (INVALID_HANDLE_VALUE == hFind)
return;
while (true)
{
if (FindFileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
{
//如果是目录
if (FindFileData.cFileName[0] != '.')
{
string strFile = "";
char szFile[MAX_PATH];
memset(szFile, 0, MAX_PATH);
strFile = lpPath;
strFile.append("\\");
wstrRPath = FindFileData.cFileName;
strFile.append(wstring_to_string(wstrRPath));
strcat(szFile, strFile.c_str());
GetAllFiles(szFile, fileList);
}
}
else
{
//如果是文件,加入到数组
wstrRPath = FindFileData.cFileName; //文件名
wstring wstrTemp = string_to_wstring(strRootPath); //根路径
wstrTemp += wstrRPath; //组合文件路径
fileList.push_back(wstrTemp);
}
if (!FindNextFile(hFind, &FindFileData)) break;
}
FindClose(hFind);
}