[英]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.