#include <windows.h>
#include <vector>
using namespace std;
BOOL IterAtorFileSaveFile(IN LPWSTR pFindPath, OUT vector<wstring>& vSaveFile)//遍历文件,并且保存文件到vector容器当中.
{
HANDLE hFind;
WIN32_FIND_DATA findData;
LARGE_INTEGER size;
hFind = FindFirstFile(pFindPath, &findData);
if (hFind == INVALID_HANDLE_VALUE)
{
OutputDebugString(TEXT("IsTowDirFileSame -> Failed to find first file!
"));
return FALSE;
}
do
{
// 忽略"."和".."两个结果
if (wcscmp(findData.cFileName, TEXT(".")) == 0 || wcscmp(findData.cFileName, TEXT("..")) == 0)
continue;
if (findData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) // 是否是目录
{
cout << findData.cFileName << " <dir>
"; //如果是目录可以进行递归调用
}
else
{
size.LowPart = findData.nFileSizeLow;
size.HighPart = findData.nFileSizeHigh;
//cout << findData.cFileName << " " << size.QuadPart << " bytes
";
//遍历出的文件以及大小. 文件可以用数据结构保存 链表类型.
vSaveFile.push_back(findData.cFileName);
}
} while (FindNextFile(hFind, &findData));
return TRUE;
}