zhangsongcui

File Search

May 6th, 2011
272
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.75 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <algorithm>
  4. #include <functional>
  5. #include <boost/ref.hpp>
  6. #include <boost/filesystem.hpp>
  7.  
  8. using namespace std;
  9. using namespace boost::filesystem;
  10.  
  11. struct file_search: binary_function<directory_entry, path, bool>
  12. {
  13.     bool operator()(const directory_entry& file, const path& filename) const
  14.     {
  15.         return file.status().type()==directory_file ?
  16.             find_if(directory_iterator(file), directory_iterator(), bind2nd(file_search(), boost::ref(filename)))!=directory_iterator() :
  17.             file.path().filename()==filename;
  18.     }
  19. };
  20.  
  21. int main()
  22. {
  23.     path filename, the_path;
  24.     cin >> filename >> the_path;
  25.     if (file_search()(directory_entry(the_path), filename))
  26.         cout << "Found!";
  27.     else
  28.         cout << "Not found!";
  29. }
Advertisement
Add Comment
Please, Sign In to add comment