static void copy_folders (CamelStore *mail_store, CamelStore *maildir_store, CamelFolderInfo *fi, CamelSession *session) { if (fi) { if (!g_str_has_prefix (fi->full_name, ".#evolution")) { gchar *maildir_folder_name; /* sanitize folder names and copy folders */ maildir_folder_name = sanitize_maildir_folder_name (fi->full_name); copy_folder ( mail_store, maildir_store, fi->full_name, maildir_folder_name); g_free (maildir_folder_name); } if (fi->child) copy_folders (mail_store, maildir_store, fi->child, session); copy_folders (mail_store, maildir_store, fi->next, session); } }
void basics::copy_folder(const bfs::path& frompath, const bfs::path& topath) { // Check whether the function call is valid if (!bfs::exists(frompath) || !bfs::is_directory(frompath)) { std::stringstream err; err << "Source directory " << frompath.string() << " does not exist or is not a directory."; throw std::runtime_error(err.str()); } if(bfs::exists(topath)) { std::stringstream err; err << "Destination directory " << topath.string() << " already exists."; throw std::runtime_error(err.str()); } // Create the destination directory if(!bfs::create_directory(topath)) { std::stringstream err; err << "Unable to create destination directory " << topath.string(); throw std::runtime_error(err.str()); } // Iterate through the source directory for(bfs::directory_iterator file(frompath); file != bfs::directory_iterator(); ++file) { bfs::path current(file->path()); if(bfs::is_directory(current)) { // Found directory: Recursion copy_folder(current, topath / current.filename()); } else { // Found file: Copy bfs::copy_file(current, topath / current.filename()); } } }