const int MAX_FILE = 1000;
TCHAR buf[MAX_FILE][MAX_PATH];
int p = 0;
void AddtoBuf(TCHAR* str)
{
memcpy(buf[p], str, sizeof(TCHAR)* MAX_PATH);
p++;
}
bool SearchDir(TCHAR* strDir);
void AppendStr(TCHAR* str, TCHAR* strSrc)
{
int c1 = _tcslen(str);
int c2 = _tcslen(strSrc);
memcpy(str+c1, strSrc, c2*sizeof(TCHAR));
}
bool DealDir(TCHAR* strDir, TCHAR* strChildDir)
{
TCHAR* s = TEXT("//");
TCHAR tempbuf[MAX_PATH];
memset(tempbuf, 0, sizeof(TCHAR)*MAX_PATH);
AppendStr(tempbuf, strDir);
AppendStr(tempbuf, s);
AppendStr(tempbuf, strChildDir);
AddtoBuf(tempbuf);
return SearchDir(tempbuf);
}
bool DealFile(TCHAR* strDir, TCHAR* strFileName)
{
TCHAR* s = TEXT("//");
TCHAR tempbuf[MAX_PATH];
memset(tempbuf, 0, sizeof(TCHAR)*MAX_PATH);
AppendStr(tempbuf, strDir);
AppendStr(tempbuf, s);
AppendStr(tempbuf, strFileName);
AddtoBuf(tempbuf);
return false;
}
bool SearchDir(TCHAR* strDir)
{
TCHAR* s = TEXT("*.*");
TCHAR* s2 = TEXT("//");
TCHAR tempbuf[MAX_PATH];
memset(tempbuf, 0, sizeof(TCHAR)*MAX_PATH);
AppendStr(tempbuf, strDir);
AppendStr(tempbuf, s2);
AppendStr(tempbuf, s);
WIN32_FIND_DATA hf;
HANDLE hFile = FindFirstFile(tempbuf, &hf);
if(INVALID_HANDLE_VALUE==hFile)
{
FindClose(hFile);
return false;
}
if (hf.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
{
DealDir(strDir, hf.cFileName);
}
else
{
DealFile(strDir, hf.cFileName);
}
bool ret = false;
while (ret=FindNextFile(hFile, &hf))
{
if (hf.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
{
DealDir(strDir, hf.cFileName);
continue;
}
else
{
DealFile(strDir, hf.cFileName);
continue;
}
}
FindClose(hFile);
return false;
}