#include <iostream>
#include <string>
#include <io.h>
#include <cstdio>
#include <cstdlib>
#include <cstring>
名前空間stdを使用します。
void HandleFile(string path、string filename)//トラバースされた各ファイルを操作する
{ ifstream inFile(path + "/" + filename);
文字列strGetLine;
if(!inFile.is_open())
{ cout << filename + "open failed!" << endl; exit(1); } while(!inFile.eof()) { getline(inFile、strGetLine); if(strGetLine.find( "new XTOOLFUNC")!= string :: npos) { // setXTOOLFUNC.insert (strGetLine.substr(strGetLine.find( "new XTOOLFUNC ")、strGetLine.find( ";")-strGetLine。 find( "new XTOOLFUNC"))); ++ setXTOOLFUNC [strGetLine.substr(strGetLine.find( "new XTOOLFUNC")、strGetLine.find( ";")-strGetLine.find( "new XTOOLFUNC"))]; } } inFile.close(); 戻る;
void fileSearch(string path)//フォルダの下の各ファイルをトラバースする
{ long hFile = 0; struct _finddata_t fileInfo; // _finddata_tファイルのさまざまな情報を格納する構造<io.h> string pathName; / *はすべてに準拠することを意味しますファイルが見つからない場合、フォルダは空です、終了します;割り当てはpathNameをクリアしてパスに設定することを意味します;追加は最後に文字列を追加することを意味し ます; c_strは constchar *の一時ポインタを返します; _findfirst:ファイルを検索して指定します名前が一致する最初のインスタンスは、成功した場合は最初のインスタンスのハンドルを返し、そうでない場合は-1Lを返します。 関数prototype:long _findfirst(char * filespec、struct _finddata_t * fileinfo); * / if((hFile = _findfirst( pathName .assign(path).append( "/ *")。c_str()、&fileInfo))== -1) return;
do
{
if(strcmp(fileInfo.name、 "..")&& strcmp(fileInfo.name、 "。")&&(fileInfo.attrib == _A_SUBDIR || fileInfo.attrib == _A_ARCH))//あります。 ..ディレクトリ、検索を入力できません; _A_SUBDIRおよび_A_ARCHは、フォルダの特定の属性を示します
{ HandleFile(path、fileInfo.name); fileSearch(path + "/" + fileInfo.name); } } while(_findnext(hFile 、&fileInfo)== 0); / * _findnextは、_findfirst関数によって提供されたファイル名に一致する次のインスタンスを検索し、成功した場合は0を返し、それ以外の場合は-1を返します 。_findcloseは検索を終了します; * / _findclose(hFile); return ; }
int main()
{{
string path = "F:/ Intranet / Li Jiangwei / Decryption / NewService";
fileSearch(パス);
system( "pause");
0を返します。
}