WCHAR FilePath[MAX_PATH * 2];
WCHAR * pstrTemp;
memset( FilePath , 0, sizeof(FilePath));
WIN32_FIND_DATA FindData;
stack<HANDLE> FindHandleStack;
HANDLE curFindHand;
BOOL FindReval;
DWORD FileCout = 0;
UpdateData();
if (!PathFileExists(m_FilePath))
{
return ;
}
wcscpy( FilePath, m_FilePath);
pstrTemp = FilePath + wcslen(FilePath) - 1;
if ( *pstrTemp != L'\\')
{
*(++pstrTemp) = L'\\';
*(++pstrTemp) = L'\0';
}
wcscat( FilePath, L"*");
LARGE_INTEGER time1, time2;
QueryPerformanceCounter( &time1);
curFindHand = FindFirstFile( FilePath, & FindData);
if (curFindHand != INVALID_HANDLE_VALUE)
{
FindHandleStack.push( curFindHand );
while(!FindHandleStack.empty())
{
if(FindNextFile( curFindHand , &FindData))
{
//查找下一个成功。
if (FindData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
{
if (wcscmp(FindData.cFileName, L".")==0 || wcscmp(FindData.cFileName , L"..")==0)
{
continue;
}
pstrTemp = wcsrchr( FilePath, L'\\');
if (pstrTemp != NULL)
{
*(++pstrTemp) = L'\0';
}
wcscat( FilePath, FindData.cFileName);
wcscat( FilePath, L"\\*");
curFindHand = FindFirstFile( FilePath, & FindData);
FindHandleStack.push( curFindHand);
}
FileCout ++;
}else{
//查找下一个失败。
FindHandleStack.pop();
FindClose(curFindHand);
if (FindHandleStack.empty())
{
break;
}else{
curFindHand = FindHandleStack.top();
//更新路径。
pstrTemp = wcsrchr( FilePath , L'\\');
if (pstrTemp != NULL)
{
*pstrTemp = L'\0';
}else{
break;
}
pstrTemp = wcsrchr( FilePath , L'\\');
if (pstrTemp != NULL)
{
*(++pstrTemp) = L'*';
*(++pstrTemp) = L'\0';
}else{
break;
}
}
}
}
}
//计算耗时。
QueryPerformanceCounter( &time2);
CString timeStr;
LARGE_INTEGER time3;
QueryPerformanceFrequency(&time3);
timeStr.Format( L"Time = %I64u second\nFileCount = %d", (time2.QuadPart-time1.QuadPart)/time3.QuadPart, FileCout);
MessageBox( timeStr);