#include "StdAfx.h" #include "findfile.h" namespace filekernel { findfile::findfile(void) { m_nlimit = nDefLimit; m_pvtfiles = NULL; m_pvtnames = NULL; m_pvtfolders = NULL; m_pvtnames_noext = NULL; } findfile::~findfile(void) { } /************************************************************************/ /* ����:iscorrectext ����:�ж�ָ���ĺ����Ƿ���Ч; ����: IN: fext �������չ��: fext�ĸ�ʽ������:_T("*.jpg|*.jpeg|*.png|*.bmp") IN lpMistakenExt ������Ҫ�����չ��; ����:���ָ������չ������Ҫ��,��TRUE,����FALSE; ע��: 1.����������չ������_T("*.*"),��TRUE;��lpMistakenExtָ����Ч,��¼��һ�η��ز�����Ҫ�����չ��; 2.fext�ĸ�ʽ������:_T("*.jpg|*.jpeg|*.png|*.bmp") */ /************************************************************************/ BOOL findfile::iscorrectext(IN const TString &fext, OUT TString* lpMistakenExt /*= NULL*/) { if (fext.size() == 0) return FALSE; if (fext.find(_T("*.*")) != TString::npos) return TRUE; TString ext = lowercase(fext); if (ext[ext.length() - 1] != _T('|')) ext.append(g_sVertical); BOOL bret = TRUE; int nIndex = 0; do { nIndex = ext.find(_T('|')); if (nIndex != TString::npos) { if (g_sCorrectExt.find(ext.substr(0, nIndex)) == TString::npos) { if (lpMistakenExt) *lpMistakenExt = ext.substr(0, nIndex); bret = FALSE; break; } ext = ext.substr(nIndex + 1); } } while (ext.find(_T('|')) != TString::npos); return bret; } /************************************************************************/ /* ����:lowercase ����:��ָ���ַ���Сд��; ����: IN Str ҪתΪСд���ַ���; ����:����תСд����ַ���; ע��: */ /************************************************************************/ TString findfile::lowercase(IN const TString &Str) { const TCHAR aazz = _T('z') - _T('Z'); TString sResult; for (TString::const_iterator it = Str.begin(); Str.end() != it; it++) { if (_T('A') <= *it && *it <= _T('Z')) sResult.append(1, *it + aazz); else sResult.append(1, *it); } return sResult; } void findfile::lowercase(IN TString& str) { TCHAR az = _T('z') - _T('Z'); for (TString::iterator it = str.begin(); it != str.end(); it++) { if (_T('A') <= *it && *it <= _T('Z')) *it += az; } } /************************************************************************/ /* ����:uppercase ����:��ָ���ַ�����д��; ����: IN Str ҪתΪ��д���ַ���; ����:����ת��д����ַ���; ע��: */ /************************************************************************/ TString findfile::uppercase(IN const TString &Str) { const TCHAR aazz = _T('z') - _T('Z'); TString sResult; for (TString::const_iterator it = Str.begin(); Str.end() != it; it++) { if (_T('a') <= *it && *it <= _T('z')) sResult.append(1, *it - aazz); else sResult.append(1, *it); } return sResult; } void findfile::uppercase(IN TString& str) { TCHAR az = _T('z') - _T('Z'); for (TString::iterator it = str.begin(); it != str.end(); it++) { if (_T('a') <= *it && *it <= _T('z')) *it -= az; } } /************************************************************************/ /* ����:match ����:�ж�ָ�����ļ������Ƿ�ƥ��ָ������չ��; ����: IN sFileExt ��չ��; IN sFile �ļ���; ����:ƥ�䷵�ط�0ֵ,����0; ע��: */ /************************************************************************/ int findfile::match(IN CONST TString &sFileExt, IN CONST TString &sFile) { TString fext = uppercase(sFileExt); TString file = uppercase(sFile); int pos = file.find_last_of(_T('.')); if (TString::npos != pos) file = file.substr(pos); return (TString::npos != fext.find(file)); } void findfile::setlimit(IN CONST INT &nLimit) { if (nLimit < 1) m_nlimit = nDefLimit; if (nLimit < nMaxLimit) m_nlimit = nLimit; } // ����ָ������չ���ļ�; void findfile::keepdownext(IN CONST TString &keepExt, IN STR_VEC &vtfiles) { if (keepExt.find(_T("*.*")) != TString::npos) return; if (!iscorrectext(keepExt) || vtfiles.size() == 0) return; // ��ȡ������չ��; int nIndex = 0; TString strtmp; TString strRemainExt(keepExt); strRemainExt.append(_T("|")); STR_VEC vtRemainExt; // ��������չ��������������; do { nIndex = strRemainExt.find(_T('|')); if (nIndex != TString::npos) { strtmp = strRemainExt.substr(0, nIndex); strRemainExt = strRemainExt.substr(nIndex + 1); if (strtmp.compare(_T("*.*"))) vtRemainExt.push_back(strtmp); } } while (strRemainExt.find(_T('|')) != TString::npos); // ���˷Ǹ�����չ�����ļ�,ͬʱȥ������ͼ,����ָ��������չ�����ļ�; for (STR_VEC::iterator it = vtfiles.begin(); it != vtfiles.end();) { BOOL bExsit = FALSE; for (STR_VEC::iterator itExt = vtRemainExt.begin(); itExt != vtRemainExt.end(); itExt++) { if (match(itExt->c_str(), it->c_str())) { bExsit = TRUE; break; } } if (!bExsit) { it = vtfiles.erase(it); continue; } it++; } } // �Ƴ�ָ����չ�����ļ�; void findfile::keepoutext(IN CONST TString &removeext, IN STR_VEC &vtfiles) { if (removeext.find(_T("*.*")) != TString::npos) return; if (!iscorrectext(removeext) || vtfiles.size() == 0) return; // ��ȡ������չ��; int nIndex = 0; TString strtmp; TString strRemoveExt(removeext); strRemoveExt.append(_T("|")); STR_VEC vtRemoveExt; // ��������չ��������������; do { nIndex = strRemoveExt.find(_T('|')); if (nIndex != TString::npos) { strtmp = strRemoveExt.substr(0, nIndex); strRemoveExt = strRemoveExt.substr(nIndex + 1); if (strtmp.compare(_T("*.*"))) vtRemoveExt.push_back(strtmp); } } while (strRemoveExt.find(_T('|')) != TString::npos); // ���˷Ǹ�����չ�����ļ�,ͬʱȥ������ͼ,����ָ��������չ�����ļ�; for (STR_VEC::iterator it = vtfiles.begin(); it != vtfiles.end();) { for (STR_VEC::iterator itExt = vtRemoveExt.begin(); itExt != vtRemoveExt.end(); itExt++) { if (match(itExt->c_str(), it->c_str())) { it = vtfiles.erase(it); break; } } it++; } } void findfile::subgroupExt(IN CONST TString &ext1, IN STR_VEC &vt1, IN CONST TString &ext2, IN STR_VEC &vt2) { // if (ext1.find(_T("*.*")) != TString::npos ) return; // if ( !iscorrectext(ext1) || vt1.size() == 0 ) return; // // // ��ȡ������չ��; // int nIndex = 0; // TString strtmp; // TString strExt1(ext1); // strExt1.append(_T("|")); // STR_VEC vtExt1; // // // ��������չ��������������; // do // { // nIndex = strExt1.find(_T('|')); // if ( nIndex != TString::npos ) // { // strtmp = strExt1.substr(0,nIndex); // strExt1 = strExt1.substr(nIndex+1); // // if(strtmp.compare(_T("*.*"))) // vtExt1.push_back(strtmp); // } // } while ( strExt1.find(_T('|')) != TString::npos ); } // ��ȡ�ļ���; TString findfile::getfilename(IN CONST TString &file) { TString name; TString strfile = file; int nIndex = strfile.find_last_of(_T('\\')); // ���file������ '\\' ,�ò����ļ���; if (nIndex == TString::npos) return _T(""); name = strfile.substr(nIndex); nIndex = name.find_last_of(_T('.')); if (nIndex == TString::npos) return _T(""); return name.substr(0, nIndex); } // ȫ��; void findfile::findall(IN CONST TString& folder, IN CONST TString& findext) { TString path = folder; if (path.size() > 0 && c_pathSeparator != path[path.size() - 1]) path.append(s_pathSeparator); TString fext = findext; if (0 == fext.compare(_T("*")) || 0 == fext.compare(_T("*.*"))) fext = _T(""); TString file = _T("*"); TString s = path + file; WIN32_FIND_DATA fileinfo = { 0 }; HANDLE handle = FindFirstFile(s.c_str(), &fileinfo); if (NULL != handle && INVALID_HANDLE_VALUE != handle) { do { // ����Ƿ������; if (checklimit()) break; // '.'�� '..'��ϵͳ�ļ�ȥ��; if (_T('.') != fileinfo.cFileName[0]) { if ((FILE_ATTRIBUTE_DIRECTORY & fileinfo.dwFileAttributes) == FILE_ATTRIBUTE_DIRECTORY) // Ŀ¼; { m_pvtfolders->push_back(path + fileinfo.cFileName); findall(path + fileinfo.cFileName, fext); } else { if (!checklimit() && (0 == fext.size() || match(fext, fileinfo.cFileName))) { m_pvtnames->push_back(fileinfo.cFileName); m_pvtfiles->push_back(path + fileinfo.cFileName); s = fileinfo.cFileName; file = s.substr(0, s.find_last_of(_T('.'))); m_pvtnames_noext->push_back(file); } } } } while (FindNextFile(handle, &fileinfo)); FindClose(handle); } } void findfile::findsubfolder(IN CONST TString& folder) { TString path = folder; if (path.size() > 0 && c_pathSeparator != path[path.size() - 1]) path.append(s_pathSeparator); TString file = _T("*"); TString s = path + file; WIN32_FIND_DATA fileinfo = { 0 }; HANDLE handle = FindFirstFile(s.c_str(), &fileinfo); if (NULL != handle && INVALID_HANDLE_VALUE != handle) { do { if (_T('.') != fileinfo.cFileName[0])// '.'�� '..'��ϵͳ�ļ�ȥ��; { if ((FILE_ATTRIBUTE_DIRECTORY & fileinfo.dwFileAttributes) == FILE_ATTRIBUTE_DIRECTORY) // Ŀ¼; { m_pvtfolders->push_back(path + fileinfo.cFileName); //findsubfolder(path+fileinfo.cFileName); // ������Ŀ¼����; } } } while (FindNextFile(handle, &fileinfo)); FindClose(handle); } } void findfile::findallsubfolder(IN CONST TString& folder) { TString path = folder; if (path.size() > 0 && c_pathSeparator != path[path.size() - 1]) path.append(s_pathSeparator); TString file = _T("*"); TString s = path + file; WIN32_FIND_DATA fileinfo = { 0 }; HANDLE handle = FindFirstFile(s.c_str(), &fileinfo); if (NULL != handle && INVALID_HANDLE_VALUE != handle) { do { if (_T('.') != fileinfo.cFileName[0])// '.'�� '..'��ϵͳ�ļ�ȥ��; { if ((FILE_ATTRIBUTE_DIRECTORY & fileinfo.dwFileAttributes) == FILE_ATTRIBUTE_DIRECTORY) // Ŀ¼; { m_pvtfolders->push_back(path + fileinfo.cFileName); findsubfolder(path + fileinfo.cFileName); // ������Ŀ¼����; } } } while (FindNextFile(handle, &fileinfo)); FindClose(handle); } } ////////////////////////////////////////////////////////////////////////// void findfile::findfiles_findin_subfolder(IN CONST TString& folder, IN CONST TString& findext) { TString path = folder; if (path.size() > 0 && c_pathSeparator != path[path.size() - 1]) path.append(s_pathSeparator); TString fext = findext; if (0 == fext.compare(_T("*")) || 0 == fext.compare(_T("*.*"))) fext = _T(""); TString file = _T("*"); TString s = path + file; WIN32_FIND_DATA fileinfo = { 0 }; HANDLE handle = FindFirstFile(s.c_str(), &fileinfo); if (NULL != handle && INVALID_HANDLE_VALUE != handle) { do { // ����Ƿ������; if (checklimit()) break; // '.'�� '..'��ϵͳ�ļ�ȥ��; if (_T('.') != fileinfo.cFileName[0]) { if ((FILE_ATTRIBUTE_DIRECTORY & fileinfo.dwFileAttributes) == FILE_ATTRIBUTE_DIRECTORY) // Ŀ¼; { findfiles_findin_subfolder(path + fileinfo.cFileName, fext); } else { if (!checklimit() && (0 == fext.size() || match(fext, fileinfo.cFileName))) { m_pvtfiles->push_back(path + fileinfo.cFileName); } } } } while (FindNextFile(handle, &fileinfo)); FindClose(handle); } } void findfile::findfiles_findout_subfolder(IN CONST TString& folder, IN CONST TString& findext) { TString path = folder; if (path.size() > 0 && c_pathSeparator != path[path.size() - 1]) path.append(s_pathSeparator); TString fext = findext; if (0 == fext.compare(_T("*")) || 0 == fext.compare(_T("*.*"))) fext = _T(""); TString file = _T("*"); TString s = path + file; WIN32_FIND_DATA fileinfo = { 0 }; HANDLE handle = FindFirstFile(s.c_str(), &fileinfo); if (NULL != handle && INVALID_HANDLE_VALUE != handle) { do { // ����Ƿ������; if (checklimit()) break; // '.'�� '..'��ϵͳ�ļ�ȥ��; if (_T('.') != fileinfo.cFileName[0]) { if ((FILE_ATTRIBUTE_DIRECTORY & fileinfo.dwFileAttributes) != FILE_ATTRIBUTE_DIRECTORY) // Ŀ¼; { if (!checklimit() && (0 == fext.size() || match(fext, fileinfo.cFileName))) { m_pvtfiles->push_back(path + fileinfo.cFileName); } } } } while (FindNextFile(handle, &fileinfo)); FindClose(handle); } } void findfile::findfiles_within_subfolder(IN CONST TString& folder, IN CONST TString& findext) { TString path = folder; if (path.size() > 0 && c_pathSeparator != path[path.size() - 1]) path.append(s_pathSeparator); TString fext = findext; if (0 == fext.compare(_T("*")) || 0 == fext.compare(_T("*.*"))) fext = _T(""); TString file = _T("*"); TString s = path + file; WIN32_FIND_DATA fileinfo = { 0 }; HANDLE handle = FindFirstFile(s.c_str(), &fileinfo); if (NULL != handle && INVALID_HANDLE_VALUE != handle) { do { // ����Ƿ������; if (checklimit()) break; // '.'�� '..'��ϵͳ�ļ�ȥ��; if (_T('.') != fileinfo.cFileName[0]) { if ((FILE_ATTRIBUTE_DIRECTORY & fileinfo.dwFileAttributes) == FILE_ATTRIBUTE_DIRECTORY) // Ŀ¼; { m_pvtfolders->push_back(path + fileinfo.cFileName); findfiles_within_subfolder(path + fileinfo.cFileName, fext); } else { if (!checklimit() && (0 == fext.size() || match(fext, fileinfo.cFileName))) { m_pvtfiles->push_back(path + fileinfo.cFileName); } } } } while (FindNextFile(handle, &fileinfo)); FindClose(handle); } } ////////////////////////////////////////////////////////////////////////// void findfile::findnames_findin_subfolder(IN CONST TString& folder, IN CONST TString& findext) { TString path = folder; if (path.size() > 0 && c_pathSeparator != path[path.size() - 1]) path.append(s_pathSeparator); TString fext = findext; if (0 == fext.compare(_T("*")) || 0 == fext.compare(_T("*.*"))) fext = _T(""); TString file = _T("*"); TString s = path + file; WIN32_FIND_DATA fileinfo = { 0 }; HANDLE handle = FindFirstFile(s.c_str(), &fileinfo); if (NULL != handle && INVALID_HANDLE_VALUE != handle) { do { // ����Ƿ������; if (checklimit()) break; // '.'�� '..'��ϵͳ�ļ�ȥ��; if (_T('.') != fileinfo.cFileName[0]) { if ((FILE_ATTRIBUTE_DIRECTORY & fileinfo.dwFileAttributes) == FILE_ATTRIBUTE_DIRECTORY) // Ŀ¼; { findnames_findin_subfolder(path + fileinfo.cFileName, fext); } else { if (!checklimit() && (0 == fext.size() || match(fext, fileinfo.cFileName))) { m_pvtnames->push_back(fileinfo.cFileName); } } } } while (FindNextFile(handle, &fileinfo)); FindClose(handle); } } void findfile::findnames_findout_subfolder(IN CONST TString& folder, IN CONST TString& findext) { TString path = folder; if (path.size() > 0 && c_pathSeparator != path[path.size() - 1]) path.append(s_pathSeparator); TString fext = findext; if (0 == fext.compare(_T("*")) || 0 == fext.compare(_T("*.*"))) fext = _T(""); TString file = _T("*"); TString s = path + file; WIN32_FIND_DATA fileinfo = { 0 }; HANDLE handle = FindFirstFile(s.c_str(), &fileinfo); if (NULL != handle && INVALID_HANDLE_VALUE != handle) { do { // ����Ƿ������; if (checklimit()) break; // '.'�� '..'��ϵͳ�ļ�ȥ��; if (_T('.') != fileinfo.cFileName[0]) { if ((FILE_ATTRIBUTE_DIRECTORY & fileinfo.dwFileAttributes) != FILE_ATTRIBUTE_DIRECTORY) // Ŀ¼; { if (!checklimit() && (0 == fext.size() || match(fext, fileinfo.cFileName))) { m_pvtnames->push_back(fileinfo.cFileName); } } } } while (FindNextFile(handle, &fileinfo)); FindClose(handle); } } void findfile::findnames_within_subfolder(IN CONST TString& folder, IN CONST TString& findext) { TString path = folder; if (path.size() > 0 && c_pathSeparator != path[path.size() - 1]) path.append(s_pathSeparator); TString fext = findext; if (0 == fext.compare(_T("*")) || 0 == fext.compare(_T("*.*"))) fext = _T(""); TString file = _T("*"); TString s = path + file; WIN32_FIND_DATA fileinfo = { 0 }; HANDLE handle = FindFirstFile(s.c_str(), &fileinfo); if (NULL != handle && INVALID_HANDLE_VALUE != handle) { do { // ����Ƿ������; if (checklimit()) break; // '.'�� '..'��ϵͳ�ļ�ȥ��; if (_T('.') != fileinfo.cFileName[0]) { if ((FILE_ATTRIBUTE_DIRECTORY & fileinfo.dwFileAttributes) == FILE_ATTRIBUTE_DIRECTORY) // Ŀ¼; { m_pvtfolders->push_back(path + fileinfo.cFileName); findnames_within_subfolder(path + fileinfo.cFileName, fext); } else { if (!checklimit() && (0 == fext.size() || match(fext, fileinfo.cFileName))) { m_pvtnames->push_back(fileinfo.cFileName); } } } } while (FindNextFile(handle, &fileinfo)); FindClose(handle); } } ////////////////////////////////////////////////////////////////////////// void findfile::findnames_findin_subfolder_ex(IN CONST TString& folder, IN CONST TString& findext) { TString path = folder; if (path.size() > 0 && c_pathSeparator != path[path.size() - 1]) path.append(s_pathSeparator); TString fext = findext; if (0 == fext.compare(_T("*")) || 0 == fext.compare(_T("*.*"))) fext = _T(""); TString file = _T("*"); TString s = path + file; WIN32_FIND_DATA fileinfo = { 0 }; HANDLE handle = FindFirstFile(s.c_str(), &fileinfo); if (NULL != handle && INVALID_HANDLE_VALUE != handle) { do { // ����Ƿ������; if (checklimit()) break; // '.'�� '..'��ϵͳ�ļ�ȥ��; if (_T('.') != fileinfo.cFileName[0]) { if ((FILE_ATTRIBUTE_DIRECTORY & fileinfo.dwFileAttributes) == FILE_ATTRIBUTE_DIRECTORY) // Ŀ¼; { findnames_findin_subfolder(path + fileinfo.cFileName, fext); } else { if (!checklimit() && (0 == fext.size() || match(fext, fileinfo.cFileName))) { s = fileinfo.cFileName; file = s.substr(0, s.find_last_of(_T('.'))); m_pvtnames_noext->push_back(file); } } } } while (FindNextFile(handle, &fileinfo)); FindClose(handle); } } void findfile::findnames_findout_subfolder_ex(IN CONST TString& folder, IN CONST TString& findext) { TString path = folder; if (path.size() > 0 && c_pathSeparator != path[path.size() - 1]) path.append(s_pathSeparator); TString fext = findext; if (0 == fext.compare(_T("*")) || 0 == fext.compare(_T("*.*"))) fext = _T(""); TString file = _T("*"); TString s = path + file; WIN32_FIND_DATA fileinfo = { 0 }; HANDLE handle = FindFirstFile(s.c_str(), &fileinfo); if (NULL != handle && INVALID_HANDLE_VALUE != handle) { do { // ����Ƿ������; if (checklimit()) break; // '.'�� '..'��ϵͳ�ļ�ȥ��; if (_T('.') != fileinfo.cFileName[0]) { if ((FILE_ATTRIBUTE_DIRECTORY & fileinfo.dwFileAttributes) != FILE_ATTRIBUTE_DIRECTORY) // Ŀ¼; { if (!checklimit() && (0 == fext.size() || match(fext, fileinfo.cFileName))) { s = fileinfo.cFileName; file = s.substr(0, s.find_last_of(_T('.'))); m_pvtnames_noext->push_back(file); } } } } while (FindNextFile(handle, &fileinfo)); FindClose(handle); } } void findfile::findnames_within_subfolder_ex(IN CONST TString& folder, IN CONST TString& findext) { TString path = folder; if (path.size() > 0 && c_pathSeparator != path[path.size() - 1]) path.append(s_pathSeparator); TString fext = findext; if (0 == fext.compare(_T("*")) || 0 == fext.compare(_T("*.*"))) fext = _T(""); TString file = _T("*"); TString s = path + file; WIN32_FIND_DATA fileinfo = { 0 }; HANDLE handle = FindFirstFile(s.c_str(), &fileinfo); if (NULL != handle && INVALID_HANDLE_VALUE != handle) { do { // ����Ƿ������; if (checklimit()) break; // '.'�� '..'��ϵͳ�ļ�ȥ��; if (_T('.') != fileinfo.cFileName[0]) { if ((FILE_ATTRIBUTE_DIRECTORY & fileinfo.dwFileAttributes) == FILE_ATTRIBUTE_DIRECTORY) // Ŀ¼; { m_pvtfolders->push_back(path + fileinfo.cFileName); findnames_within_subfolder(path + fileinfo.cFileName, fext); } else { if (!checklimit() && (0 == fext.size() || match(fext, fileinfo.cFileName))) { s = fileinfo.cFileName; file = s.substr(0, s.find_last_of(_T('.'))); m_pvtnames_noext->push_back(file); } } } } while (FindNextFile(handle, &fileinfo)); FindClose(handle); } } ////////////////////////////////////////////////////////////////////////// void findfile::findfilesnames_findin_subfolder(IN CONST TString& folder, IN CONST TString& findext) { TString path = folder; if (path.size() > 0 && c_pathSeparator != path[path.size() - 1]) path.append(s_pathSeparator); TString fext = findext; if (0 == fext.compare(_T("*")) || 0 == fext.compare(_T("*.*"))) fext = _T(""); TString file = _T("*"); TString s = path + file; WIN32_FIND_DATA fileinfo = { 0 }; HANDLE handle = FindFirstFile(s.c_str(), &fileinfo); if (NULL != handle && INVALID_HANDLE_VALUE != handle) { do { // ����Ƿ������; if (checklimit()) break; // '.'�� '..'��ϵͳ�ļ�ȥ��; if (_T('.') != fileinfo.cFileName[0]) { if ((FILE_ATTRIBUTE_DIRECTORY & fileinfo.dwFileAttributes) == FILE_ATTRIBUTE_DIRECTORY) // Ŀ¼; { findfilesnames_findin_subfolder(path + fileinfo.cFileName, fext); } else { if (!checklimit() && (0 == fext.size() || match(fext, fileinfo.cFileName))) { m_pvtnames->push_back(fileinfo.cFileName); m_pvtfiles->push_back(path + fileinfo.cFileName); } } } } while (FindNextFile(handle, &fileinfo)); FindClose(handle); } } void findfile::findfilesnames_findout_subfolder(IN CONST TString& folder, IN CONST TString& findext) { TString path = folder; if (path.size() > 0 && c_pathSeparator != path[path.size() - 1]) path.append(s_pathSeparator); TString fext = findext; if (0 == fext.compare(_T("*")) || 0 == fext.compare(_T("*.*"))) fext = _T(""); TString file = _T("*"); TString s = path + file; WIN32_FIND_DATA fileinfo = { 0 }; HANDLE handle = FindFirstFile(s.c_str(), &fileinfo); if (NULL != handle && INVALID_HANDLE_VALUE != handle) { do { // ����Ƿ������; if (checklimit()) break; // '.'�� '..'��ϵͳ�ļ�ȥ��; if (_T('.') != fileinfo.cFileName[0]) { if ((FILE_ATTRIBUTE_DIRECTORY & fileinfo.dwFileAttributes) != FILE_ATTRIBUTE_DIRECTORY) // Ŀ¼; { if (!checklimit() && (0 == fext.size() || match(fext, fileinfo.cFileName))) { m_pvtnames->push_back(fileinfo.cFileName); m_pvtfiles->push_back(path + fileinfo.cFileName); } } } } while (FindNextFile(handle, &fileinfo)); FindClose(handle); } } void findfile::findfilesnames_within_subfolder(IN CONST TString& folder, IN CONST TString& findext) { TString path = folder; if (path.size() > 0 && c_pathSeparator != path[path.size() - 1]) path.append(s_pathSeparator); TString fext = findext; if (0 == fext.compare(_T("*")) || 0 == fext.compare(_T("*.*"))) fext = _T(""); TString file = _T("*"); TString s = path + file; WIN32_FIND_DATA fileinfo = { 0 }; HANDLE handle = FindFirstFile(s.c_str(), &fileinfo); if (NULL != handle && INVALID_HANDLE_VALUE != handle) { do { // ����Ƿ������; if (checklimit()) break; // '.'�� '..'��ϵͳ�ļ�ȥ��; if (_T('.') != fileinfo.cFileName[0]) { if ((FILE_ATTRIBUTE_DIRECTORY & fileinfo.dwFileAttributes) == FILE_ATTRIBUTE_DIRECTORY) // Ŀ¼; { m_pvtfolders->push_back(fileinfo.cFileName); findfilesnames_within_subfolder(path + fileinfo.cFileName, fext); } else { if (!checklimit() && (0 == fext.size() || match(fext, fileinfo.cFileName))) { m_pvtnames->push_back(fileinfo.cFileName); m_pvtfiles->push_back(path + fileinfo.cFileName); } } } } while (FindNextFile(handle, &fileinfo)); FindClose(handle); } } void findfile::findfilesnames_findin_subfolder_ex(IN CONST TString& folder, IN CONST TString& findext) { TString path = folder; if (path.size() > 0 && c_pathSeparator != path[path.size() - 1]) path.append(s_pathSeparator); TString fext = findext; if (0 == fext.compare(_T("*")) || 0 == fext.compare(_T("*.*"))) fext = _T(""); TString file = _T("*"); TString s = path + file; WIN32_FIND_DATA fileinfo = { 0 }; HANDLE handle = FindFirstFile(s.c_str(), &fileinfo); if (NULL != handle && INVALID_HANDLE_VALUE != handle) { do { // ����Ƿ������; if (checklimit()) break; // '.'�� '..'��ϵͳ�ļ�ȥ��; if (_T('.') != fileinfo.cFileName[0]) { if ((FILE_ATTRIBUTE_DIRECTORY & fileinfo.dwFileAttributes) == FILE_ATTRIBUTE_DIRECTORY) // Ŀ¼; { findfilesnames_findin_subfolder(path + fileinfo.cFileName, fext); } else { if (!checklimit() && (0 == fext.size() || match(fext, fileinfo.cFileName))) { m_pvtfiles->push_back(path + fileinfo.cFileName); s = fileinfo.cFileName; file = s.substr(0, s.find_last_of(_T('.'))); m_pvtnames_noext->push_back(file); } } } } while (FindNextFile(handle, &fileinfo)); FindClose(handle); } } void findfile::findfilesnames_findout_subfolder_ex(IN CONST TString& folder, IN CONST TString& findext) { TString path = folder; if (path.size() > 0 && c_pathSeparator != path[path.size() - 1]) path.append(s_pathSeparator); TString fext = findext; if (0 == fext.compare(_T("*")) || 0 == fext.compare(_T("*.*"))) fext = _T(""); TString file = _T("*"); TString s = path + file; WIN32_FIND_DATA fileinfo = { 0 }; HANDLE handle = FindFirstFile(s.c_str(), &fileinfo); if (NULL != handle && INVALID_HANDLE_VALUE != handle) { do { // ����Ƿ������; if (checklimit()) break; // '.'�� '..'��ϵͳ�ļ�ȥ��; if (_T('.') != fileinfo.cFileName[0]) { if ((FILE_ATTRIBUTE_DIRECTORY & fileinfo.dwFileAttributes) == FILE_ATTRIBUTE_DIRECTORY) // Ŀ¼; { findfilesnames_findout_subfolder_ex(path + fileinfo.cFileName, fext); } else { if (!checklimit() && (0 == fext.size() || match(fext, fileinfo.cFileName))) { m_pvtfiles->push_back(path + fileinfo.cFileName); s = fileinfo.cFileName; file = s.substr(0, s.find_last_of(_T('.'))); m_pvtnames_noext->push_back(file); } } } } while (FindNextFile(handle, &fileinfo)); FindClose(handle); } } void findfile::findfilesnames_within_subfolder_ex(IN CONST TString& folder, IN CONST TString& findext) { TString path = folder; if (path.size() > 0 && c_pathSeparator != path[path.size() - 1]) path.append(s_pathSeparator); TString fext = findext; if (0 == fext.compare(_T("*")) || 0 == fext.compare(_T("*.*"))) fext = _T(""); TString file = _T("*"); TString s = path + file; WIN32_FIND_DATA fileinfo = { 0 }; HANDLE handle = FindFirstFile(s.c_str(), &fileinfo); if (NULL != handle && INVALID_HANDLE_VALUE != handle) { do { // ����Ƿ������; if (checklimit()) break; // '.'�� '..'��ϵͳ�ļ�ȥ��; if (_T('.') != fileinfo.cFileName[0]) { if ((FILE_ATTRIBUTE_DIRECTORY & fileinfo.dwFileAttributes) == FILE_ATTRIBUTE_DIRECTORY) // Ŀ¼; { m_pvtfolders->push_back(fileinfo.cFileName); findfilesnames_within_subfolder_ex(path + fileinfo.cFileName, fext); } else { if (!checklimit() && (0 == fext.size() || match(fext, fileinfo.cFileName))) { m_pvtfiles->push_back(path + fileinfo.cFileName); s = fileinfo.cFileName; file = s.substr(0, s.find_last_of(_T('.'))); m_pvtnames_noext->push_back(file); } } } } while (FindNextFile(handle, &fileinfo)); FindClose(handle); } } };