|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html><head><meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1">
<title>MTParserLib: MTSearchFile.cpp Source File</title>
<link href="doxygen.css" rel="stylesheet" type="text/css">
</head><body>
<!-- Generated by Doxygen 1.4.4 -->
<div class="qindex"><a class="qindex" href="main.html">Main Page</a> | <a class="qindex" href="namespaces.html">Namespace List</a> | <a class="qindex" href="hierarchy.html">Class Hierarchy</a> | <a class="qindex" href="annotated.html">Class List</a> | <a class="qindex" href="files.html">File List</a> | <a class="qindex" href="namespacemembers.html">Namespace Members</a> | <a class="qindex" href="functions.html">Class Members</a> | <a class="qindex" href="globals.html">File Members</a></div>
<h1>MTSearchFile.cpp</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="preprocessor">#include "<a class="code" href="MTSearchFile_8h.html">MTSearchFile.h</a>"</span>
<a name="l00002"></a>00002 <span class="preprocessor">#include <windows.h></span>
<a name="l00003"></a>00003
<a name="l00004"></a><a class="code" href="classMTSearchFile.html#a1">00004</a> <span class="keywordtype">void</span> <a class="code" href="classMTSearchFile.html#a1">MTSearchFile::search</a>(<span class="keyword">const</span> std::vector<MTSTRING> &directories, <span class="keyword">const</span> std::vector<MTSTRING> &searchPatterns, std::vector<MTSTRING> &results)
<a name="l00005"></a>00005 {
<a name="l00006"></a>00006 results.clear();
<a name="l00007"></a>00007
<a name="l00008"></a>00008 <span class="keywordflow">for</span>( <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> t=0; t < directories.size(); t++ )
<a name="l00009"></a>00009 {
<a name="l00010"></a>00010 <span class="comment">// the path must end with a /</span>
<a name="l00011"></a>00011 <a class="code" href="MTUnicodeANSIDefs_8h.html#a0">MTSTRING</a> dir = directories[t];
<a name="l00012"></a>00012
<a name="l00013"></a>00013 <span class="keywordflow">if</span>( dir[dir.size()-1] != <span class="charliteral">'/'</span> &&
<a name="l00014"></a>00014 dir[dir.size()-1] != <span class="charliteral">'\\'</span> )
<a name="l00015"></a>00015 {
<a name="l00016"></a>00016 dir += _T(<span class="stringliteral">"/"</span>);
<a name="l00017"></a>00017 }
<a name="l00018"></a>00018
<a name="l00019"></a>00019 <a class="code" href="classMTSearchFile.html#a1">search</a>(dir.c_str(), searchPatterns, results);
<a name="l00020"></a>00020 }
<a name="l00021"></a>00021 }
<a name="l00022"></a>00022
<a name="l00023"></a>00023 <span class="keywordtype">void</span> <a class="code" href="classMTSearchFile.html#a1">MTSearchFile::search</a>(<span class="keyword">const</span> <a class="code" href="MTUnicodeANSIDefs_8h.html#a1">MTCHAR</a> *directory, <span class="keyword">const</span> std::vector<MTSTRING> &searchPatterns, std::vector<MTSTRING> &results)
<a name="l00024"></a>00024 {
<a name="l00025"></a>00025 <span class="comment">// file search</span>
<a name="l00026"></a>00026 <span class="keywordflow">for</span>( <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> t=0; t<searchPatterns.size(); t++ )
<a name="l00027"></a>00027 {
<a name="l00028"></a>00028 <a class="code" href="classMTSearchFile.html#a1">search</a>( directory, searchPatterns[t].c_str(), results );
<a name="l00029"></a>00029 }
<a name="l00030"></a>00030
<a name="l00031"></a>00031 <span class="comment">// now, we look for subfolders </span>
<a name="l00032"></a>00032 WIN32_FIND_DATA findData;
<a name="l00033"></a>00033 HANDLE hFind;
<a name="l00034"></a>00034 <a class="code" href="MTUnicodeANSIDefs_8h.html#a0">MTSTRING</a> curLookIn = directory;
<a name="l00035"></a>00035 curLookIn += _T(<span class="stringliteral">"*.*"</span>);
<a name="l00036"></a>00036
<a name="l00037"></a>00037 hFind = FindFirstFile( curLookIn.c_str() , &findData);
<a name="l00038"></a>00038
<a name="l00039"></a>00039 <span class="keywordflow">if</span>( hFind != INVALID_HANDLE_VALUE )
<a name="l00040"></a>00040 {
<a name="l00041"></a>00041 <span class="keywordflow">do</span>
<a name="l00042"></a>00042 {
<a name="l00043"></a>00043 <span class="comment">// if this is a sub-folder then search it</span>
<a name="l00044"></a>00044 <span class="keywordflow">if</span>( findData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY &&
<a name="l00045"></a>00045 findData.cFileName[0] != <span class="charliteral">'.'</span> )
<a name="l00046"></a>00046 {
<a name="l00047"></a>00047 <a class="code" href="MTUnicodeANSIDefs_8h.html#a0">MTSTRING</a> curLookDir = directory;
<a name="l00048"></a>00048 curLookDir += findData.cFileName;
<a name="l00049"></a>00049 curLookDir += _T(<span class="stringliteral">"/"</span>);
<a name="l00050"></a>00050
<a name="l00051"></a>00051 <a class="code" href="classMTSearchFile.html#a1">search</a>( curLookDir.c_str(), searchPatterns, results );
<a name="l00052"></a>00052 }
<a name="l00053"></a>00053
<a name="l00054"></a>00054 }<span class="keywordflow">while</span>( FindNextFile(hFind, &findData) );
<a name="l00055"></a>00055 }
<a name="l00056"></a>00056
<a name="l00057"></a>00057 FindClose(hFind);
<a name="l00058"></a>00058 }
<a name="l00059"></a>00059
<a name="l00060"></a>00060 <span class="keywordtype">void</span> <a class="code" href="classMTSearchFile.html#a1">MTSearchFile::search</a>(<span class="keyword">const</span> <a class="code" href="MTUnicodeANSIDefs_8h.html#a1">MTCHAR</a> *directory, <span class="keyword">const</span> <a class="code" href="MTUnicodeANSIDefs_8h.html#a1">MTCHAR</a> *searchPattern, std::vector<MTSTRING> &results)
<a name="l00061"></a>00061 {
<a name="l00062"></a>00062 WIN32_FIND_DATA findData;
<a name="l00063"></a>00063 <a class="code" href="MTUnicodeANSIDefs_8h.html#a0">MTSTRING</a> curLookIn = directory;
<a name="l00064"></a>00064 curLookIn += searchPattern;
<a name="l00065"></a>00065
<a name="l00066"></a>00066 HANDLE hFind = FindFirstFile(curLookIn.c_str(), &findData);
<a name="l00067"></a>00067
<a name="l00068"></a>00068 <span class="keywordflow">if</span>( hFind != INVALID_HANDLE_VALUE )
<a name="l00069"></a>00069 {
<a name="l00070"></a>00070 <span class="keywordflow">do</span>
<a name="l00071"></a>00071 {
<a name="l00072"></a>00072 <span class="comment">// skip directories and special files named "."</span>
<a name="l00073"></a>00073 <span class="keywordflow">if</span>( !(findData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) &&
<a name="l00074"></a>00074 findData.cFileName[0] != <span class="charliteral">'.'</span> )
<a name="l00075"></a>00075 {
<a name="l00076"></a>00076 <a class="code" href="MTUnicodeANSIDefs_8h.html#a0">MTSTRING</a> found = directory;
<a name="l00077"></a>00077 found += findData.cFileName;
<a name="l00078"></a>00078 results.push_back( found );
<a name="l00079"></a>00079 }
<a name="l00080"></a>00080
<a name="l00081"></a>00081 }<span class="keywordflow">while</span>( FindNextFile(hFind, &findData) );
<a name="l00082"></a>00082 }
<a name="l00083"></a>00083
<a name="l00084"></a>00084 FindClose(hFind);
<a name="l00085"></a>00085 }
</pre></div><hr size="1"><address style="align: right;"><small>Generated on Sun Mar 9 17:39:36 2008 for MTParserLib by
<a href="http://www.doxygen.org/index.html">
<img src="doxygen.png" alt="doxygen" align="middle" border="0"></a> 1.4.4 </small></address>
</body>
</html>
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.