Advertisement
Glenpl

skrypt do kompresowania zdjęć

Jun 25th, 2015
312
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.57 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <vector>
  4.  
  5. #define BOOST_FILESYSTEM_VERSION 3
  6. #define BOOST_FILESYSTEM_NO_DEPRECATED
  7. #include <boost/filesystem.hpp>
  8.  
  9. using namespace ::boost::filesystem;
  10.  
  11. void get_all_files_of_given_extension(const path& root, const std::string& ext, std::vector<path>& ret)
  12. {
  13.     if(!exists(root) || !is_directory(root)) return;
  14.  
  15.     recursive_directory_iterator it(root);
  16.     recursive_directory_iterator endit;
  17.  
  18.     while(it != endit)
  19.     {
  20.         if(is_regular_file(*it) && it->path().extension() == ext) ret.push_back(it->path().filename());
  21.         ++it;
  22.     }
  23. }
  24.  
  25. int main()
  26. {
  27.     std::vector<path> filenames;
  28.     get_all_files_of_given_extension(current_path(), ".jpg", filenames);
  29.  
  30.     std::cout << filenames.size() << " matching files found\n\n";
  31.     std::cout << "wait while processing files\n\n";
  32.  
  33.     int i = 0;
  34.  
  35.     for( auto filename : filenames )
  36.     {
  37.         // cjpeg-static -quality 80 plik1.jpg > plik1-mozjpg.jpg
  38.  
  39.         std::string command = "cjpeg-static.exe -quality 80 ";
  40.         command += filename.string() + " > mini_" + filename.string();
  41.  
  42.         std::cout << "processing file...\n";
  43.         system( command.c_str() );
  44.         std::cout << "file processed\n";
  45.         std::cout << filename.string() << " -> mini_" << filename.string() << "\n";
  46.  
  47.         ++i;
  48.         std::cout << i << " files processed\n\n";
  49.     }
  50.  
  51.     std::cout << "all (" << i << ") files processed successfully\n\n";
  52.     std::cout << "press enter to exit";
  53.  
  54.     std::cin.sync();
  55.     std::cin.get();
  56.     return 0;
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement