zoukankan      html  css  js  c++  java
  • 遍历文件夹

     //返回.exe的文件名
    
    void FindExeFile(std::string path, std::string mode, std::set<std::string> &saveExeFile)
    {
    _finddata_t file;
    intptr_t HANDLE;
    std::string pattern{ "(.*).exe" };
    std::regex reg(pattern);
    std::string Onepath = path + mode;
    HANDLE = _findfirst(Onepath.c_str(), &file);
    if (HANDLE == -1L)
    {
    LOG_WARN << "can not match the folder path";
    return;
    }
    do
    {
    //判断是否有子目录
    if (file.attrib & _A_SUBDIR)
    {
    //判断是否为"."当前目录,".."上一层目录
    if ((strcmp(file.name, ".") != 0) && (strcmp(file.name, "..") != 0))
    {
    std::string newPath = path + "\" + file.name;
    FindExeFile(newPath, mode, saveExeFile);
    }
    }
    else
    {
    bool ret = std::regex_match(file.name, reg);
    
    //找到.exe文件
    if (ret)
    {
    saveExeFile.insert(file.name);
    }
    }
    } while (_findnext(HANDLE, &file) == 0);
    _findclose(HANDLE);
    }
    
    
    
    
    
        //返回.exe所在的绝对路径
    
    void FindExeFileWithPath(std::string path, std::string mode, std::set<std::string> &saveExeFile)
    
    {
    _finddata_t file;
    intptr_t HANDLE;
    std::string pattern{ "(.*).exe" };
    std::regex reg(pattern);
    std::string Onepath = path + mode;
    HANDLE = _findfirst(Onepath.c_str(), &file);
    if (HANDLE == -1L)
    {
    return;
    }
    do
    {
    //判断是否有子目录
    if (file.attrib & _A_SUBDIR)
    {
    //判断是否为"."当前目录,".."上一层目录
    if ((strcmp(file.name, ".") != 0) && (strcmp(file.name, "..") != 0))
    {
    std::string newPath = path + "\" + file.name;
    FindExeFile(newPath, mode, saveExeFile);
    }
    }
    else
    {
    bool ret = std::regex_match(file.name, reg);
    
    //找到.exe文件
    if (ret)
    {
    saveExeFile.insert(path + "\" + file.name);
    }
    }
    } while (_findnext(HANDLE, &file) == 0);
    _findclose(HANDLE);
    }
    
    
    
    void main()
    
    {
    
      std::vector<std::string> exeFile;
    
          std::string path="C:\Windows";
    
         std::mode="*\*";
    
         FindExeFile(path, mode, exeFile);
    }
  • 相关阅读:
    IE7下元素的 'paddingtop' 遇到 'clear' 特性在某些情况下复制到 'paddingbottom'
    Foundation HTML5 Canvas中的2处错误
    近期学习技术安排
    2011年工作总结和展望(上篇)
    详解ObjectiveC消息传递机制
    ObjectiveC 2.0的运行时编程消息转发
    c# Pdf 转换图片
    c语言指针用法难点
    C# web实现word 转Html、office转Html、pdf转图片 在线预览文件
    ObjectiveC中什么是类
  • 原文地址:https://www.cnblogs.com/gd-luojialin/p/12214701.html
Copyright © 2011-2022 走看看