简体   繁体   English

有什么方法可以检查文件名是否存在包含正则表达式的文件

[英]Is there any way to check whether a file exist with a file name contains regular expression

Given the path you are search under, and the file name contains regular expression, is there any way to check whether there is any file satisfy the file name pattern exists under this path? 给定您要搜索的路径,并且文件名包含正则表达式,是否有任何方法可以检查是否有任何文件满足此路径下存在的文件名模式? In C++?? 在C ++中? for example: under path 例如:在路径下

/path

I want to search the file "foo.*" 我想搜索文件“ foo。*”

foo.* 

the result could be foo.1 or foo.2 or whatever. 结果可能是foo.1或foo.2等。 I would like to get the result(I mean I want to know whether the file exist and the exact file name), Thanks 我想要得到结果(我的意思是我想知道文件是否存在以及确切的文件名),谢谢

Look into boost::filesystem , otherwise you will need to look at the api for your os. 查看boost :: filesystem ,否则您将需要查看操作系统的api。

Here is an example (untested): 这是一个示例(未经测试):

boost::filesystem::path dir("/path");
boost::filesystem::directory_iterator it(dir), end;
BOOST_FOREACH(const boost::filesystem::path& p, std::make_pair(it, end))
{
    if(boost::filesystem::is_regular_file(p))
    {
        if(p.stem().string() == "foo")
        {
            std::cout << p.extension() << '\n';
        }
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何检查zip文件或压缩文件是否存在? - How to check whether a zip file or compressed file is exist? 检查文件夹中是否已经存在文件名? - Check whether file name already exists in a folder or not? 如何检查特定文件夹中是否有文件? - How to check if any file exist in specific folder? 检查一个文件是否包含另一个文件 - Check if a file contains another file 如何打开任何包含单词或数字的输入文件并打印出来。 C ++ - How to open any input file whether it contains words or numbers and prints it out. C++ 检查String是否包含字典文件中的单词的快速方法? - Fast way to check if String contains a word from a dictionary file? 检查std :: string是否包含任何小写字符? - Check std::string whether contains any lowercase character? c ++中是否有任何功能可以检查在特定路径中给定的文件是否为脚本(.sh)文件 - is there any function in c++ to check whether a file given in a specific path is a script(.sh) file or not 保存文件时,有没有办法设置qfiledialog的默认文件名 - Is there any way to set the default file name of qfiledialog while saving file 有没有一种方法可以检查字符串是否在C ++中包含Unicode字符 - Is there a way to check whether a string contains unicode characters in C++
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM