Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <fstream>
- #include <iostream>
- #include <experimental/filesystem>
- #include <boost/program_options.hpp>
- #include <iostream>
- #include <string>
- using namespace boost::program_options;
- using std::string;
- namespace fs = std::experimental::filesystem;
- int main(int argc, char *argv[])
- {
- options_description desc{"Options"};
- desc.add_options()
- ("help,h", "Help for arguments")
- ("source,s", value<string>()->default_value("/home/yuriy/projects/temp/source"),
- "Folder you want to copy from")
- ("dest,d", value<string>()->default_value("/home/yuriy/projects/temp/dist"),
- "Folder you want to copy into")
- ("filter,f", value<string>()->default_value("bar"),
- "Name of parent folder you want to use for filter");
- variables_map vm;
- store(parse_command_line(argc, argv, desc), vm);
- notify(vm);
- if (vm.count("help"))
- {
- std::cout << desc << '\n';
- }
- std::cout << "source: " << vm["source"].as<string>() << '\n';
- std::cout << "dest: " << vm["dest"].as<string>() << '\n';
- string dest = vm["dest"].as<string>();
- int copied_size =0;
- for(fs::directory_entry p : fs::recursive_directory_iterator(vm["source"].as<string>()))
- {
- if (p.status().type() == fs::file_type::regular)
- {
- fs::path iterFilePath = p.path();
- if (iterFilePath.parent_path().filename() == vm["filter"].as<string>())
- {
- fs::copy(iterFilePath, dest);
- copied_size += fs::file_size(iterFilePath);
- std::cout << iterFilePath << '\n';
- }
- }
- }
- std::cout << "devi: " << copied_size / (1024*1024.) << '\n';
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement