得到指定目录下的子文件夹列表, 这个程序哪儿有错?
总是获得的子文件夹列表中少了一个文件夹
VOID CServerFile::GetDirDirList(char* sPath, list<CString>& strList)
{
string str;
str = sPath;
str.append(_T("\\*.*"));
CFileFind mFileFind;
CString strTemp;
BOOL bRet = mFileFind.FindFile(str.c_str());
if(bRet) bRet = mFileFind.FindNextFile();
else return; while(bRet)
{
strTemp = mFileFind.GetFileName();
if((mFileFind.IsDirectory()) && (!mFileFind.IsDots()) )
{
strList.push_back(strTemp);
}
bRet = mFileFind.FindNextFile();
}
mFileFind.Close();
}
总是获得的子文件夹列表中少了一个文件夹
VOID CServerFile::GetDirDirList(char* sPath, list<CString>& strList)
{
string str;
str = sPath;
str.append(_T("\\*.*"));
CFileFind mFileFind;
CString strTemp;
BOOL bRet = mFileFind.FindFile(str.c_str());
if(bRet) bRet = mFileFind.FindNextFile();
else return; while(bRet)
{
strTemp = mFileFind.GetFileName();
if((mFileFind.IsDirectory()) && (!mFileFind.IsDots()) )
{
strList.push_back(strTemp);
}
bRet = mFileFind.FindNextFile();
}
mFileFind.Close();
}
{
WIN32_FIND_DATA fd;
char folder[MAX_PATH];
int i; if (path == NULL)
return; memset(folder, 0, MAX_PATH);
sprintf(folder, "%s\\*.*", path);
HANDLE hFind = ::FindFirstFile (folder, & fd );
if (hFind != INVALID_HANDLE_VALUE)
{
do
{
if ( fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY )
{
CString name = fd.cFileName;
if ( name != _T (".") && name != _T("..") )
{
char subfolder[MAX_PATH];
memset(subfolder, 0, MAX_PATH);
sprintf(subfolder, "%s\\%s", path, fd.cFileName);
TRACE ( _T ( " Folder: %s\n " ), subfolder );
//::SetCurrentDirectory ( fd.cFileName );
EnumerateFolder (subfolder);
::SetCurrentDirectory (_T (".."));
}
}
else
{ TRACE ( _T ( "File: %s\n " ), fd.cFileName );
}
} while ( ::FindNextFile ( hFind, & fd) );
::FindClose ( hFind );
}
}
使用这个系统的API的方式,确实是正确的...但是我还是想弄清楚,为什么我那样做就会有错... 郁闷死了...
-_-# 不要忽悠我哦...其实在这里这个while do 和do while 是一样的...
他两的唯一不一样处,是在于最初是否判断哦
{
string str;
str = sPath;
str.append(_T("\\*.*")); CFileFind mFileFind; CString strTemp; BOOL bRet ;
do{
bRet= mFileFind.FindFile(str.c_str());
if(bRet)
bRet = mFileFind.FindNextFile();
else break;
strTemp = mFileFind.GetFileName();
if((mFileFind.IsDirectory()) && (!mFileFind.IsDots()) )
{
strList.push_back(strTemp);
}
bRet = mFileFind.FindNextFile();
} while(bRet)
mFileFind.Close();
}