Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<unordered_map>
- #include<boost/filesystem.hpp>
- namespace fs = boost::filesystem;
- void function(std::string path1, std::string path2)
- {
- typedef std::unordered_multimap<long, std::string>map_type;
- int i = 1;
- auto currpath1 = fs::path(path1);
- auto currpath2 = fs::path(path2);
- map_type map1, map2, result;
- map_type::iterator iter1, iter2, iter3;
- // get list of files in the first directory
- std::cout<<"\n";
- std::cout << currpath1 <<" contains : "<<std::endl;
- for(auto pt : fs::directory_iterator(currpath1))
- {
- auto path = pt.path();
- if (fs::is_regular(path))
- {
- map1.insert(std::make_pair(fs::file_size(path), path.filename().string() ));
- std::cout<<i << ". " << fs::file_size(path)<<" bytes"<<"\t\t"<< path.filename().string()<<std::endl;
- i++;
- }
- else
- {
- std::cout<<"\n";
- }
- }
- // get list of files in second directory
- std::cout<<"\n";
- std::cout << currpath2 <<" contains : "<<std::endl;
- i = 1;
- for(auto pt : fs::directory_iterator(currpath2))
- {
- auto path = pt.path();
- if (fs::is_regular(path))
- {
- map2.insert(std::make_pair(fs::file_size(path), path.filename().string() ));
- std::cout<<i << ". " << fs::file_size(path)<<" bytes"<<"\t\t"<< path.filename().string()<<std::endl;
- i++;
- }
- else
- {
- std::cout<<"\n";
- }
- }
- for(iter1 = map1.begin(); iter1!=map1.end(); iter1++)
- {
- for(iter2 = map2.begin(); iter2!=map2.end(); iter2++)
- {
- if(iter1->first == iter2 ->first)
- {
- result.insert(std::make_pair(iter1->first, iter1->second ));
- result.insert(std::make_pair(iter2->first, iter2->second ));
- }
- }
- }
- std::cout<<"\n";
- i = 1;
- std::cout<< " common files : "<<std::endl;
- for(iter3 = result.begin(); iter3!=result.end(); iter3++)
- {
- std::cout<<i << ". " << iter3->first <<" bytes"<< "\t\t"<< iter3->second<<std::endl;
- i++;
- }
- }
- int main()
- {
- std::string input1, input2;
- std::getline(std::cin, input1);
- std::getline(std::cin, input2) ;
- function(input1, input2);
- }
Advertisement
Add Comment
Please, Sign In to add comment