123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129 |
- #ifndef __FIND_FILES_COLLECTION__
- #define __FIND_FILES_COLLECTION__
- #ifndef WIN32
- #error now only for WIN32(platform).
- #endif
- #include <string>
- #include <vector>
- using namespace std;
- #ifdef UNICODE
- typedef wstring TString;
- #else
- typedef string TString;
- #endif
- #pragma once
- // advanced find files collection;
- namespace affsco
- {
- CONST INT nMaxLimit = 0x100000; //--1048576
- CONST INT nDefLimit = 0x10000; //--65536
- CONST TCHAR c_pathSeparator = _T('\\');
- CONST TString s_pathSeparator = _T("\\");
- class Implffsco
- {
- INT m_nLimit;
- INT m_nIsonym; // ÎļþÃûÏàͬµÄ´ÎÊý;
- BOOL m_bFindSubFolders;
- vector<TString> m_vtAllFiles;
- vector<TString> m_vtSubFolders;
- vector<TString> m_vtFiles;
- vector<TString> m_vtJustFNames;
- private:
- inline INT CheckLimit() {
- return GetAllFilesCount() == GetLimit();
- }
- inline static TString 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;
- }
- public:
- Implffsco(void);
- ~Implffsco(void);
- static int Match(IN CONST TString &sExt, IN CONST TString &sFile);
- TString GetFileName(CONST INT &nPos = 0){
- return m_vtAllFiles.at(nPos);
- }
- INT GetAllFilesCount() {
- return m_vtFiles.size() + m_vtSubFolders.size();
- }
- INT GetFilesCount() {
- return m_vtFiles.size();
- }
- INT GetDirsCount(){
- return m_vtSubFolders.size();
- }
- CONST vector<TString> &GetAllFiles()CONST {
- return m_vtAllFiles;
- }
- CONST vector<TString> &GetFiles()CONST {
- return m_vtFiles;
- }
- CONST vector<TString> &GetSubFolders()CONST {
- return m_vtSubFolders;
- }
- CONST vector<TString> &GetFNames()CONST {
- return m_vtJustFNames;
- }
- INT GetLimit() const {
- return m_nLimit;
- }
- inline void SetLimit(IN CONST INT &nLimit) {
- if(nLimit < 1)
- m_nLimit = nDefLimit;
- if (nLimit < nMaxLimit )
- m_nLimit = nLimit;
- }
- BOOL IsFindSubFolders() const {
- return m_bFindSubFolders;
- }
- void SetFindDir(BOOL bFindSubFolders=TRUE) {
- m_bFindSubFolders = bFindSubFolders;
- }
- BOOL IsaDirectory(CONST TString &sDirectory){
- return (FILE_ATTRIBUTE_DIRECTORY == GetFileAttributes(sDirectory.c_str()));
- }
- VOID ReCleart(){
- m_vtAllFiles.clear();
- m_vtFiles.clear();
- m_vtSubFolders.clear();
- m_vtJustFNames.clear();
- }
- VOID FindFiles(IN CONST TString& sTargetDirectory, IN CONST TString& sFileExt);
- VOID FindFilesEx(IN CONST TString& sTargetDirectory, IN CONST TString& sFileExt);
- VOID JustFindNames(IN CONST TString& sTargetDirectory, IN CONST TString& sFileExt);
- };
- };
- #endif
|