Boost logo

Boost Users :

From: Rajesh Jadhav (rajesh.jadhav_at_[hidden])
Date: 2007-09-10 15:23:49


Hello All,

I am trying to create a directory structure having 4 to 5 levels. When I try
to call the boost::filesystem::create_directories(src); It throws an
exception saying that path does not exist .So isn't create_directories()
mean't for creating directory structure recursively or is there a other api
which does it. I could not find Api's which can split the path ,and give
the directory names in the path starting after the root directory up to leaf
directory .

I am attaching the sample code .

#include <iostream>
#include "boost/filesystem/operations.hpp"
#include "boost/filesystem/path.hpp"
#include "boost/filesystem/convenience.hpp"
int main()
{
    const char* srcPath = "C:\\tmp\\dir1\\dir2\\dir3\\"; (this structure
does not exist)
    boost::filesystem::path src = boost::filesystem::path(srcPath,
boost::filesystem::no_check);

    try
    {
       boost::filesystem::create_directories(relativepath); // throws
exception
        if(src.has_branch_path())
        {
            boost::filesystem::path branchpath = src.branch_path();
            std::cout << branchpath.string(); // prints C:
            boost::filesystem::path rootpath = src.root_path();
            std::cout << rootpath.string(); //prints C:
            boost::filesystem::path relativepath = src.relative_path();
            std::cout << relativepath.string(); //prints
tmp\\dir1\\dir2\\dir3\\

        }

    }
    catch(std::exception& ex)
       {
           std::cout << ex.what() << std::endl;
       }

return 0;
}

Thanks in advance for the replies.

Rajesh



Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net