Guest User

Untitled

a guest
Feb 20th, 2018
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.25 KB | None | 0 0
  1. #include <boost/filesystem.hpp>
  2. #include <string>
  3. #include <iostream>
  4. #include <sstream>
  5. using namespace boost::filesystem;
  6.  
  7. //****************************************************************************************
  8.  
  9. int main()
  10. {
  11.           bool recurse = true;
  12. // C:\Users\admin\Desktop\testgo
  13. path pathDest = "C:\\Users\\admin\\Desktop\\testgo";
  14. int a = 1;
  15.  
  16. // using namespace boost::filesystem;
  17.  
  18. recursive_directory_iterator it("C:\\Users\\admin\\Desktop\\test"), end;
  19. for (; it != end; ++it)
  20. {
  21.                    
  22.     if (!recurse)
  23.     {
  24.         it.no_push(); // disable recurse
  25.     } // end if
  26.  
  27.     if (!is_regular_file(*it))
  28.     {
  29.         continue;
  30.     }  // end if
  31.  
  32.     // make the validity check
  33.     auto filepath = it->path();
  34.        
  35.     // check if the fileextension is .bmp
  36.  
  37.     try
  38.     {
  39.         if(filepath.extension() == ".bmp")
  40.         {
  41.             // rename(const path& old_p, const path& new_p);
  42.             std::ostringstream os;
  43.             os << a <<".bmp";          
  44.             //copy_file(filepath, pathDest);
  45.             //dont need this since copy file can also rename it //rename(pathDest, pathDest/os.str());
  46.                            
  47.             copy_file(filepath, pathDest/os.str());
  48.             a++;
  49.          
  50.         } // end if
  51.     }// end try
  52.     catch(const std::exception& e )
  53.     {
  54.         std::cout<< "abc: "<< e.what() << "\n" ;
  55.     }
  56.      
  57.        
  58.     } // end for
  59. }
Add Comment
Please, Sign In to add comment