OpenMPCD
FilesystemUtilities.cpp
2 
4 
5 #include <boost/filesystem.hpp>
6 
7 using namespace OpenMPCD;
8 
9 void FilesystemUtilities::ensureDirectory(const std::string& path)
10 {
11  boost::system::error_code ec;
12  boost::filesystem::create_directories(path, ec);
13 
14  if(ec)
15  OPENMPCD_THROW(IOException, "Failed to create directory.");
16 }
17 
18 void FilesystemUtilities::ensureParentDirectory(const std::string& path)
19 {
20  boost::filesystem::path p(path);
21 
22  if(!p.has_parent_path())
23  return;
24 
25  boost::system::error_code ec;
26  boost::filesystem::create_directories(p.parent_path(), ec);
27 
28  if(ec)
29  OPENMPCD_THROW(IOException, "Failed to create directory.");
30 }
Exceptions.hpp
OPENMPCD_THROW
#define OPENMPCD_THROW(ExceptionType, message)
Throws the given ExceptionType, passing the given message along with file and line number information...
Definition: Exceptions.hpp:22
OpenMPCD::FilesystemUtilities::ensureDirectory
static void ensureDirectory(const std::string &path)
Ensures that the given directory exists, creating it and its parents if necessary.
Definition: FilesystemUtilities.cpp:9
FilesystemUtilities.hpp
OpenMPCD::IOException
Error on IO.
Definition: Exceptions.hpp:160
OpenMPCD::FilesystemUtilities::ensureParentDirectory
static void ensureParentDirectory(const std::string &path)
Ensures that the parent directory of the path given exists.
Definition: FilesystemUtilities.cpp:18