bool recursive_copy()

in include/poac/io/file/path.hpp [84:120]


    bool recursive_copy(
        const boost::filesystem::path &from,
        const boost::filesystem::path &dest )
    {
        namespace fs = boost::filesystem;

        // Does the copy source exist?
        if (!fs::exists(from) || !fs::is_directory(from)) {
//            std::cerr << "Could not validate `from` dir" << std::endl;
            return EXIT_FAILURE;
        }
        // Does the copy destination exist?
        if (!validate_dir(dest) && !fs::create_directories(dest)) {
//            std::cerr << "Could not validate `dest` dir" << std::endl;
            return EXIT_FAILURE; // Unable to create destination directory
        }

        // Iterate through the source directory
        for (fs::directory_iterator file(from); file != fs::directory_iterator(); ++file) {
            fs::path current(file->path());
            if (fs::is_directory(current)) {
                // Found directory: Recursion
                if (recursive_copy(current, dest / current.filename()))
                    return EXIT_FAILURE;
            }
            else {
                // Found file: Copy
                boost::system::error_code err;
                fs::copy_file(current, dest / current.filename(), err);
                if (err) {
//                    std::cerr << err.message() << std::endl;
                    return EXIT_FAILURE;
                }
            }
        }
        return EXIT_SUCCESS;
    }