How can I create directory tree in C++/Linux?

Lipis picture Lipis · Mar 23, 2009 · Viewed 201.4k times · Source

I want an easy way to create multiple directories in C++/Linux.

For example I want to save a file lola.file in the directory:

/tmp/a/b/c

but if the directories are not there I want them to be created automagically. A working example would be perfect.

Answer

Benoît picture Benoît · Mar 23, 2009

Easy with Boost.Filesystem: create_directories

#include <boost/filesystem.hpp>
//...
boost::filesystem::create_directories("/tmp/a/b/c");

Returns: true if a new directory was created, otherwise false.