Boost C++ Libraries of the most highly regarded and expertly designed C++ library projects in the world. Herb Sutter and Andrei Alexandrescu, C++ Coding Standards

This is the documentation for an old version of boost. Click here for the latest Boost documentation.


//  libs/filesystem/src/convenience.cpp  -------------------------------------//

//  � Copyright Beman Dawes, 2002
//  � Copyright Vladimir Prus, 2002
//  Use, modification, and distribution is subject to the Boost Software
//  License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at

//  See library home page at


// define BOOST_FILESYSTEM_SOURCE so that <boost/filesystem/config.hpp> knows
// the library is being built (possibly exporting rather than importing code)

#include <boost/filesystem/convenience.hpp>

#include <boost/config/abi_prefix.hpp> // must be the last header

namespace boost
  namespace filesystem

//  create_directories (contributed by Vladimir Prus)  -----------------------//

     BOOST_FILESYSTEM_DECL void create_directories(const path& ph)
         if (ph.empty() || exists(ph)) return;

         // First create branch, by calling ourself recursively
         // Now that parent's path exists, create the directory

    BOOST_FILESYSTEM_DECL std::string extension(const path& ph)
      std::string leaf = ph.leaf();

      std::string::size_type n = leaf.rfind('.');
      if (n != std::string::npos)
        return leaf.substr(n);
        return std::string();

    BOOST_FILESYSTEM_DECL std::string basename(const path& ph)
      std::string leaf = ph.leaf();

      std::string::size_type n = leaf.rfind('.');
      return leaf.substr(0, n);

    BOOST_FILESYSTEM_DECL path change_extension(const path& ph, const std::string& new_extension)
      return ph.branch_path() / (basename(ph) + new_extension);

  } // namespace filesystem
} // namespace boost