123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180 |
- #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);
- }
- }
- };
|