检查文件中是否存在带有通配符的文件 [英] check if file exists with wildcards in filename

查看:759
本文介绍了检查文件中是否存在带有通配符的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要为c ++:

  if(fileExists(c:\foo\bar * .txt )){
cout<< 文件已存在;
} else {
cout<< file does not exist;
}

它与这里描述的几乎相同:如何检查文件是否在Java中有通配符?,但是对于c ++

解决方案

由于您没有指定平台,因此有几个选项。对于POSIX兼容系统,有此解决方案的答案(信用他不是我的):


您可以使用[ glob()] [1 ] POSIX库函数。


或者对于窗口有


链接到 setargv。 obj (或 wsetargv.obj )和argv []将会为你类似于Unix shell的做法:





我无法保证


或者对于一个简单的跨平台库,您可以尝试 shwild wildcmp ,或使用此问题的答案自行编写。 / p>

What i Need for c++:

if( fileExists("c:\foo\bar*.txt") ){
  cout << "file exists";
}else{
  cout << "file does not exists";
}

Its nearly the same as descripted here: How to check a file if exists with wildcard in Java? , but for c++

解决方案

Since you haven't specified a platform there are a few options. For POSIX compliant systems there is the answer from this solution (credit his not mine):

You can use the [glob()][1] POSIX library function.

alternatively for windows there is this solution:

Link with setargv.obj (or wsetargv.obj) and argv[] will be globbed for you similar to how the Unix shells do it:

I can't vouch for how well it does it though.

Or for a simple cross platform library you could try shwild or wildcmp or write your own with the answer to this question.

这篇关于检查文件中是否存在带有通配符的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆