how do you check if a directory exists and create it if it doesn't in c++?

Started by
3 comments, last by localplayer 16 years, 2 months ago
How do you check if a directory exists and create it if it doesn't? For example, I am writing a screenshot function and I want to save it in a screenshots folder, but I am uncertian that it is there on execution, thus would like to create it so I can save my screenshot, otherwise it will not write it to a non existant directory. Thanks. *I am aiming for platform independance, so I hope it does not need the windows api EDIT: forgot to mention I am using C++ [Edited by - biohaz on February 5, 2008 12:37:12 AM]
Advertisement
Which language are you using?

In C++ there is no built in way to do this. Have a look at the boost libraries though, as they provide a very good filesystem library.
Other languages may provide this feature as a built in, but we need more details to answer your question.
oops, yea using c++. I thought it was not built in, otherwise I would have found it by now. I guess I will look for the boost library for it. Thanks
Boost is very worthwhile. Highly recommended. It's (C++)++.

You might be able to get away with

system("mkdir foo");

Try the following POSIX functions.

stat - get file/dir status
mkdir - make a directory

regards,

chris.

This topic is closed to new replies.

Advertisement