[英]Is there any way to check whether a file exist with a file name contains regular expression
给定您要搜索的路径,并且文件名包含正则表达式,是否有任何方法可以检查是否有任何文件满足此路径下存在的文件名模式? 在C ++中? 例如:在路径下
/path
我想搜索文件“ foo。*”
foo.*
结果可能是foo.1或foo.2等。 我想要得到结果(我的意思是我想知道文件是否存在以及确切的文件名),谢谢
查看boost :: filesystem ,否则您将需要查看操作系统的api。
这是一个示例(未经测试):
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.