Advertisement
Guest User

Untitled

a guest
Mar 27th, 2017
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.75 KB | None | 0 0
  1. #include <fstream>
  2. #include <iostream>
  3. #include <experimental/filesystem>
  4. #include <boost/program_options.hpp>
  5. #include <iostream>
  6. #include <string>
  7.  
  8. using namespace boost::program_options;
  9. using std::string;
  10. namespace fs = std::experimental::filesystem;
  11.  
  12. int main(int argc, char *argv[])
  13. {
  14. options_description desc{"Options"};
  15. desc.add_options()
  16. ("help,h", "Help for arguments")
  17. ("source,s", value<string>()->default_value("/home/yuriy/projects/temp/source"),
  18. "Folder you want to copy from")
  19. ("dest,d", value<string>()->default_value("/home/yuriy/projects/temp/dist"),
  20. "Folder you want to copy into")
  21. ("filter,f", value<string>()->default_value("bar"),
  22. "Name of parent folder you want to use for filter");
  23.  
  24. variables_map vm;
  25. store(parse_command_line(argc, argv, desc), vm);
  26. notify(vm);
  27. if (vm.count("help"))
  28. {
  29. std::cout << desc << '\n';
  30. }
  31. std::cout << "source: " << vm["source"].as<string>() << '\n';
  32. std::cout << "dest: " << vm["dest"].as<string>() << '\n';
  33. string dest = vm["dest"].as<string>();
  34. int copied_size =0;
  35. for(fs::directory_entry p : fs::recursive_directory_iterator(vm["source"].as<string>()))
  36. {
  37. if (p.status().type() == fs::file_type::regular)
  38. {
  39. fs::path iterFilePath = p.path();
  40. if (iterFilePath.parent_path().filename() == vm["filter"].as<string>())
  41. {
  42. fs::copy(iterFilePath, dest);
  43. copied_size += fs::file_size(iterFilePath);
  44. std::cout << iterFilePath << '\n';
  45. }
  46. }
  47. }
  48. std::cout << "devi: " << copied_size / (1024*1024.) << '\n';
  49. return 0;
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement