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);
    }
  • 相关阅读:
    JS_ECMA基本语法中的几种封装的小函数-1
    DOM_06之定时器、事件、cookie
    DOM_05之DOM、BOM常用对象
    OC数组中文排序
    uiwebview加载中文URL
    ios判断点击的坐标点
    获取字符串在另一个字符串中出现的次数
    NSFileHandle
    NSFileManager
    NSData
  • 原文地址:https://www.cnblogs.com/gd-luojialin/p/12214701.html
Copyright © 2011-2022 走看看