Jenifa

filesystem

May 14th, 2019
155
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.45 KB | None | 0 0
  1. #include<iostream>
  2. #include<unordered_map>
  3. #include<boost/filesystem.hpp>
  4.  
  5.  
  6. namespace fs = boost::filesystem;
  7.  
  8.  
  9.  
  10. void function(std::string path1, std::string path2)
  11. {
  12.  
  13.     typedef std::unordered_multimap<long, std::string>map_type;
  14.  
  15.     int i = 1;
  16.  
  17.     auto currpath1 = fs::path(path1);
  18.  
  19.     auto currpath2 = fs::path(path2);
  20.  
  21.     map_type map1, map2, result;
  22.  
  23.     map_type::iterator iter1, iter2, iter3;
  24.  
  25.  
  26.  
  27. // get list of files in the first directory
  28.  
  29.     std::cout<<"\n";
  30.  
  31.     std::cout << currpath1 <<" contains : "<<std::endl;
  32.  
  33.     for(auto pt : fs::directory_iterator(currpath1))
  34.     {
  35.  
  36.         auto path = pt.path();
  37.  
  38.         if (fs::is_regular(path))
  39.         {
  40.             map1.insert(std::make_pair(fs::file_size(path), path.filename().string() ));
  41.  
  42.             std::cout<<i << ". " << fs::file_size(path)<<" bytes"<<"\t\t"<< path.filename().string()<<std::endl;
  43.  
  44.             i++;
  45.         }
  46.         else
  47.         {
  48.             std::cout<<"\n";
  49.         }
  50.     }
  51.  
  52.  
  53. // get list of files in second directory
  54.  
  55.     std::cout<<"\n";
  56.  
  57.  
  58.     std::cout << currpath2 <<" contains : "<<std::endl;
  59.  
  60.     i = 1;
  61.  
  62.     for(auto pt : fs::directory_iterator(currpath2))
  63.     {
  64.  
  65.         auto path = pt.path();
  66.  
  67.         if (fs::is_regular(path))
  68.         {
  69.             map2.insert(std::make_pair(fs::file_size(path), path.filename().string() ));
  70.  
  71.             std::cout<<i << ". " << fs::file_size(path)<<" bytes"<<"\t\t"<< path.filename().string()<<std::endl;
  72.  
  73.             i++;
  74.         }
  75.         else
  76.         {
  77.             std::cout<<"\n";
  78.         }
  79.     }
  80.  
  81.  
  82.  
  83.     for(iter1 = map1.begin(); iter1!=map1.end(); iter1++)
  84.     {
  85.         for(iter2 = map2.begin();  iter2!=map2.end(); iter2++)
  86.         {
  87.  
  88.             if(iter1->first == iter2 ->first)
  89.             {
  90.                 result.insert(std::make_pair(iter1->first, iter1->second ));
  91.  
  92.                 result.insert(std::make_pair(iter2->first, iter2->second ));
  93.             }
  94.  
  95.  
  96.         }
  97.  
  98.     }
  99.  
  100.  
  101.     std::cout<<"\n";
  102.  
  103.         i = 1;
  104.  
  105.     std::cout<< " common files : "<<std::endl;
  106.  
  107.     for(iter3 = result.begin();  iter3!=result.end(); iter3++)
  108.     {
  109.  
  110.         std::cout<<i << ". " << iter3->first <<" bytes"<< "\t\t"<< iter3->second<<std::endl;
  111.  
  112.         i++;
  113.  
  114.     }
  115.  
  116.  
  117.  
  118.  
  119. }
  120.  
  121. int main()
  122. {
  123.      std::string input1, input2;
  124.  
  125.          std::getline(std::cin, input1);
  126.  
  127.          std::getline(std::cin, input2) ;
  128.  
  129.          function(input1, input2);
  130.  
  131.  
  132.  
  133. }
Advertisement
Add Comment
Please, Sign In to add comment