PreDirectory(CString DirName)
{
LPTSTR lpBuffer;
UINT uSize;
CString fileName;
HANDLE hHeap;
HANDLE hFindFile;
WIN32_FIND_DATA FindFileData;
uSize=(GetCurrentDirectory(0,NULL))*sizeof(TCHAR);
hHeap=GetProcessHeap();
lpBuffer = (LPTSTR)HeapAlloc(hHeap,HEAP_ZERO_MEMORY,uSize);
GetCurrentDirectory(uSize,lpBuffer);
if(lpBuffer!=DirName)
{
SetCurrentDirectory(DirName); //调整当前目录
}
hFindFile=FindFirstFile(_T("*.*"),&FindFileData);
CString tFile;
if(hFindFile!=INVALID_HANDLE_VALUE)
{
do
{
tFile=FindFileData.cFileName;
if((tFile==_T("."))||(tFile==_T(".."))) continue;
if(FindFileData.dwFileAttributes==FILE_ATTRIBUTE_DIRECTORY)
{
if(DirName[DirName.GetLength()-1]!=_T('\\'))
PreDirectory(DirName+ _T('\\')+tFile);
else
PreDirectory(DirName+tFile);
}
else
{
//Process(tFile);//处理文件tFile
CString fn;
fn = DirName + _T("\\");
fn+=tFile;
//AfxMessageBox(fn);
m_fList.Add(fn);
}
}
while(FindNextFile(hFindFile,&FindFileData));
FindClose(hFindFile);
}
else
{
SetCurrentDirectory(lpBuffer);
}
SetCurrentDirectory(lpBuffer); //回复到原来的目录下
}