扫瞄c盘所有文件 并且正则匹配浏览器缓存文件路径

本文介绍了一个使用C++ Boost库中的regex组件来匹配特定文件路径的应用案例。通过递归查找指定目录下的所有文件,并利用正则表达式判断文件路径是否符合预设模式,实现了对文件的有效筛选。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

// 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;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值