#include "StdAfx.h" #include "Implffsco.h" //extern void IsonymLog(LPCTSTR lpLog,BOOL bLogModel); namespace affsco { Implffsco::Implffsco(void) { m_nLimit = nDefLimit; m_nIsonym = 0; m_bFindSubFolders = FALSE; } Implffsco::~Implffsco(void) { m_vtAllFiles.clear(); m_vtFiles.clear(); m_vtJustFNames.clear(); m_vtSubFolders.clear(); } int Implffsco::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 Implffsco::FindFiles(IN CONST TString& sTargetDirectory, IN CONST TString& sFileExt) { TString path = sTargetDirectory; if (path.size() > 0 && c_pathSeparator != path[path.size() - 1]) path.append(s_pathSeparator); TString fext = sFileExt; 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 (m_bFindSubFolders) { m_vtSubFolders.push_back(path + fileinfo.cFileName); FindFiles(path+fileinfo.cFileName,fext); } } else { //--limit test if (!CheckLimit() && (0 == fext.size() || Match(fext, fileinfo.cFileName))) { m_vtFiles.push_back(path + fileinfo.cFileName); } } } } while (FindNextFile(handle, &fileinfo)); FindClose(handle); } } VOID Implffsco::FindFilesEx(IN CONST TString& sTargetDirectory, IN CONST TString& sFileExt) { TString path = sTargetDirectory; if (path.size() > 0 && c_pathSeparator != path[path.size() - 1]) path.append(s_pathSeparator); TString fext = sFileExt; 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 (m_bFindSubFolders) { m_vtSubFolders.push_back(path + fileinfo.cFileName); FindFilesEx(path+fileinfo.cFileName,fext); } } else { //--limit test if (!CheckLimit() && (0 == fext.size() || Match(fext, fileinfo.cFileName))) { m_vtFiles.push_back(path + fileinfo.cFileName); m_vtJustFNames.push_back(fileinfo.cFileName); } } } } while (FindNextFile(handle, &fileinfo)); FindClose(handle); } } VOID Implffsco::JustFindNames(IN CONST TString& sTargetDirectory, IN CONST TString& sFileExt) { TString path = sTargetDirectory; if (path.size() > 0 && c_pathSeparator != path[path.size() - 1]) path.append(s_pathSeparator); TString fext = sFileExt; 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) // 目录; { JustFindNames(path+fileinfo.cFileName,fext); } else { //--limit test if (!CheckLimit() && (0 == fext.size() || Match(fext, fileinfo.cFileName))) { m_vtJustFNames.push_back(fileinfo.cFileName); } } } } while (FindNextFile(handle, &fileinfo)); FindClose(handle); } } };