1

I am looking for a C++ routine which will check if a given path can be successfully created on the system? The routine should not actually create a path but return true if the path can be successfully created?

Thanks..

CSP
  • 11
  • 1

1 Answers1

1

You can put your code that tries to create the path in a try catch block..

WeaselFox
  • 7,220
  • 8
  • 44
  • 75
  • Yeah but if it succeeds the path will be created. – Jongware Jul 28 '13 at 14:51
  • This is the only real solution. There's no way to ensure that a path can be created (lots of unexpected things can go wrong at runtime), so when you actually want to create it, you'll *still* have to handle errors. Might as well just do it that way the first time. – Cody Gray - on strike Jul 28 '13 at 15:11
  • Right. Plus, if you are able to successfully create a directory, you are also able to delete it (if this is not the right time to actually create it). So, no harm done. – Mr Lister Jul 28 '13 at 15:13
  • Ageed, but there are a few very simple checks that can be done *before* even attempting to create the path. A difference between *could* and *would*, perhaps. – Jongware Jul 28 '13 at 15:22