// TestRrgex0401.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include "TestRrgex0401.h"
#include<boost/regex.hpp>
#include<string>
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
// The one and only application object
CWinApp theApp;
using namespace std;
using namespace boost;
BOOL Regexmatch( string m_strFilePath)
{
regex reg("C:\\\\Users\\\\[\\s\\S]+\\\\AppData\\\\Local\\\\Microsoft\\\\Windows\\\\Temporary\\sInternet\\sFiles\\\\Content\\.IE5\\\\[a-zA-Z0-9]+\\\\([a-zA-Z0-9]|\[[a-zA-Z0-9]*\])+\\.htm");
if (regex_match(m_strFilePath,reg))
{
cout<<"匹配成功"<<endl;
return TRUE;
}
}
void FindFilepath(CString lpfile)
{
CFileFind tempFind;
BOOL bFound;
bFound = tempFind.FindFile(lpfile +_T("\\*.*"));
CString strFilePath ;
while(bFound) //遍历所有文件
{
bFound=tempFind.FindNextFile();
if(tempFind.IsDots()) continue; //如果找到的是返回上层的目录 则结束本次查找
if(tempFind.IsDirectory()) //找到的是文件夹,则遍历该文件夹下的文件
{
CString m_cstemp;
m_cstemp = tempFind.GetFilePath();
m_cstemp+=_T("\\*.*");
FindFilepath(m_cstemp);
strFilePath=tempFind.GetFilePath();
FindFilepath(strFilePath);
}else{
strFilePath=tempFind.GetFilePath(); //获取文件的完整路径
CString cs = strFilePath;
char szStrtemp[MAX_PATH] ;
memset(szStrtemp,0,sizeof(szStrtemp));
if (wcstombs(szStrtemp, cs, cs.GetLength()) != -1)
{
BOOL m_Bl = Regexmatch(szStrtemp); //正则匹配
if (m_Bl == TRUE)
{
cout<<szStrtemp<<endl;
memset(szStrtemp,0,sizeof(szStrtemp));
}
}
}
}
tempFind.Close();
}
int _tmain(int argc, TCHAR* argv[], TCHAR* envp[])
{
int nRetCode = 0;
HMODULE hModule = ::GetModuleHandle(NULL);
CString lpfile = _T("C:\\");
FindFilepath(lpfile);
system("pause");
return nRetCode;
}