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