-1

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++

Community
  • 1
  • 1
Mhh Lecker
  • 984
  • 1
  • 9
  • 20
  • 1
    Currently [this](https://stackoverflow.com/questions/1257721/can-i-use-a-mask-to-iterate-files-in-a-directory-with-boost) is the closest you'll get to a cross platform solution in C++. Otherwise, there may be platform specific APIs available. – Praetorian Jul 04 '14 at 08:07
  • 1
    Since a file system is a concurrent data structure, you should beware that "existence" of a file is not really a meaningful, or even sensible, property. The question "Does file X exist?" has no meaningful answer that you could distinguish from any different answer. I could always answer "yes", and claim that someone just deleted the file as you were about to open it, and you couldn't prove I was wrong. The only meaningful operation on a file system is to *open* a file, which may either succeed or not. – Kerrek SB Jul 04 '14 at 08:28

1 Answers1

1

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.

Community
  • 1
  • 1
Mike H-R
  • 7,726
  • 5
  • 43
  • 65