��
/*! @function ******************************************************************************** <PRE> ������ : GetAllSubDirs ���� : ������з�����������Ŀ¼�б� ���� : [OUT] vResult : ���������� [IN] dirPattern : Ҫ���ҵ���Ŀ¼ͨ��� [IN] includeSubdir : �Ƿ������Ŀ¼ [IN] includeHidden : �Ƿ��������Ŀ¼ [IN] includeDot : �Ƿ������.���͡�..��ϵͳĿ¼ ����ֵ : ������������Ŀ¼���� �׳��쳣 : - -------------------------------------------------------------------------------- ��ע : �����Ƿ�ɹ���vResult�е�ԭ���ݶ�������� �����÷� : - -------------------------------------------------------------------------------- ���� : ���� </PRE> *******************************************************************************/ ULONG CDir::GetAllSubDirs(OUT VSTR& vResult, IN tstringEx dirPattern /*= byT("*")*/, IN bool includeSubdir /*= false*/, IN bool includeHidden /*= true*/, IN bool includeDot /*= false*/) const { // ========================================================================= // = ��ʼ�� vResult.clear(); if (dirPattern.empty() || !IsValid()) { return 0; }
WIN32_FIND_DATA FindFileData; HANDLE hFind; tstringEx Pattern = m_basedir + DELIMITER + dirPattern;
// ========================================================================= // = ƥ����Ŀ¼ hFind = ::FindFirstFile(Pattern.c_str(), &FindFileData); if(INVALID_HANDLE_VALUE == hFind) return 0; } tstringEx stDir; if (-1 != (n=dirPattern.find_last_of(ALLDELIMITERS))) { stDir = m_basedir + DELIMITER + dirPattern.substr(0, n) + DELIMITER; } else { stDir = m_basedir + DELIMITER; }
do { if (!(FindFileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) { goto findnext; }
if (IsDotDir(FindFileData.cFileName) && !includeDot) { goto findnext; }
if ((FindFileData.dwFileAttributes & FILE_ATTRIBUTE_HIDDEN) && !includeHidden) { goto findnext; }
// �ݹ�������Ŀ¼ if (includeSubdir && !IsDotDir(FindFileData.cFileName)) { VSTR rr; tstringEx rdir; if (-1 != n) { rdir = dirPattern.substr(0, n)+DELIMITER+FindFileData.cFileName +DELIMITER+dirPattern.substr(n+1, -1); } else { rdir = FindFileData.cFileName+DELIMITER+dirPattern; }
GetAllSubDirs(rr, rdir, includeSubdir, includeHidden, includeDot); const ULONG count = rr.size(); for (ULONG i=0; i<count; ++i) { vResult.push_back(rr[i]); } } // if (includeSubdir && !IsDotDir(FindFileData.cFileName))
vResult.push_back(stDir + FindFileData.cFileName);
findnext: if (!::FindNextFile(hFind, &FindFileData)) { break; } } while(true);
::FindClose(hFind); return vResult.size(); } |
��