TNB Library
TnbDeepFileFinder.h
[詳解]
1#pragma once
11#include "TnbFileFinder.h"
12
13
14
15//TNB Library
16namespace TNB
17{
18
19
20
33template<typename TYP = CFileFinder>
35{
36public:
37
39 CDeepFileFinderT(void) : m_depth(0), m_continue(true), m_result(0)
40 {
41 #ifdef _DEBUG
42 TYP ff;
43 CAbstractFileFinder* P = &ff; // ここでエラー出る場合、 TYP に CAbstractFileFinder のサブクラスを指定して無い可能性があります。
45 #endif
46 }
47
53 DWORD Execute(LPCTSTR lpszPath)
54 {
55 m_depth = 0;
56 m_continue = true;
57 m_result = 0;
58 m_Find(lpszPath);
59 return m_result;
60 }
61
62protected:
63
70 void OndemandStop(DWORD result)
71 {
72 m_result = result;
73 m_continue = false;
74 }
75
84 virtual void OnStartFindFolder(TYP& finder, LPCTSTR lpszTargetPath, int depth)
85 {
86 }
87
98 virtual bool OnFoundFolder(LPCTSTR lpszFoundFolder, const WIN32_FIND_DATA& data, int depth)
99 {
100 ::OutputDebugString(_T("OnFoundFolder("));
101 ::OutputDebugString(lpszFoundFolder);
102 ::OutputDebugString(_T(")\n"));
103 return true;
104 }
105
114 virtual void OnFoundFile(LPCTSTR lpszFoundName, const WIN32_FIND_DATA& data, int depth)
115 {
116 ::OutputDebugString(_T("OnFoundFile("));
117 ::OutputDebugString(lpszFoundName);
118 ::OutputDebugString(_T(")\n"));
119 }
120
121private:
122 int m_depth;
123 bool m_continue;
124 DWORD m_result;
125 // 検索処理
126 void m_Find(LPCTSTR lpszPath)
127 {
128 m_depth++;
129 if ( m_continue )
130 {
131 TYP ff;
132 OnStartFindFolder(ff, lpszPath, m_depth);
133 if ( m_continue && ff.Start(lpszPath, _T("\\*")) )
134 {
135 do
136 {
137 CStr fileName = ff->cFileName;
138 CStr fullPath;
139 fullPath.Format(_T("%s\\%s"), lpszPath, fileName);
140 if ( (ff->dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0 )
141 {
142 // Dir
143 if ( OnFoundFolder(fullPath, ff.Get(), m_depth) )
144 {
145 m_Find(fullPath);
146 }
147 }
148 else
149 {
150 OnFoundFile(fullPath, ff.Get(), m_depth);
151 }
152 }
153 while ( m_continue && ff.Next() );
154 }
155 }
156 m_depth--;
157 }
158};
159
160
161
174
175
176
177}; // TNB
ファイル検索関係のヘッダ
ファイル検索抽象クラス
Definition: TnbFileFinder.h:33
ディープファイル検索クラス
virtual bool OnFoundFolder(LPCTSTR lpszFoundFolder, const WIN32_FIND_DATA &data, int depth)
[通知] フォルダ発見通知.
CDeepFileFinderT(void)
コンストラクタ
virtual void OnFoundFile(LPCTSTR lpszFoundName, const WIN32_FIND_DATA &data, int depth)
[通知] ファイル発見通知.
void OndemandStop(DWORD result)
[依頼] 停止依頼.
DWORD Execute(LPCTSTR lpszPath)
[実行] 検索開始.
virtual void OnStartFindFolder(TYP &finder, LPCTSTR lpszTargetPath, int depth)
[通知] フォルダ検索開始通知.
void Format(const TYP *lpszFormat,...)
[代入] 書式付き文字列代入.
Definition: TnbStr.h:359
CDeepFileFinderT CDeepFileFinder
ディープファイル検索クラス
void IgnoreUnusedValue(const T &value)
[宣言] 参照しない値宣言.
Definition: TnbDef.h:434
TNB Library
Definition: TnbDoxyTitle.txt:2