Advertisement
Scarlet

Screenshot Sorter Console

Nov 3rd, 2018
192
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.17 KB | None | 0 0
  1. #include <iostream>
  2. using std::cin;
  3. using std::cout;
  4. using std::endl;
  5.  
  6. #include <fstream>
  7. using std::ifstream;
  8. using std::ofstream;
  9.  
  10. #include <map>
  11. using std::map;
  12.  
  13. #include <array>
  14. using std::array;
  15.  
  16. #include <filesystem>
  17. using std::experimental::filesystem::path;
  18. using std::experimental::filesystem::recursive_directory_iterator;
  19. using std::experimental::filesystem::create_directories;
  20. using std::experimental::filesystem::exists;
  21. using std::experimental::filesystem::copy;
  22. using std::experimental::filesystem::remove;
  23.  
  24. #include <string>
  25. using std::string;
  26. using std::getline;
  27.  
  28. const array<char, 9> PROHIBITED_CHARACTERS
  29. {
  30.     '\\', '/', ':', '*', '?', '"', '<', '>', '|'
  31. };
  32.  
  33. int main()
  34. {
  35.     map<string, string> gameList;
  36.     ifstream knownGamesIn;
  37.     knownGamesIn.open("GameIDs.txt");
  38.     if (knownGamesIn.is_open())
  39.     {
  40.         string currentLine, gameID, gameName;
  41.         int tabPos;
  42.         while (getline(knownGamesIn, currentLine))
  43.         {
  44.             tabPos = currentLine.find('\t');
  45.             gameID = currentLine.substr(0, tabPos);
  46.             gameName = currentLine.substr(tabPos + 1);
  47.  
  48.             gameList[gameID] = gameName;
  49.         }
  50.  
  51.         knownGamesIn.close();
  52.     }
  53.  
  54.     ofstream knownGamesOut;
  55.  
  56.     string switchAlbumPath = "no swatch";
  57.     for (char drive = 'A'; drive <= 'Z' && switchAlbumPath == "no swatch"; drive++)
  58.     {
  59.         string tmp(1, drive);
  60.         tmp += ":\\Nintendo\\Album";
  61.         if (exists(tmp)) switchAlbumPath = tmp;
  62.     }
  63.  
  64.     int totalFiles = 0;
  65.     int currentFile = 1;
  66.     path current;
  67.  
  68.     cout << "Getting total number of files..." << endl;
  69.     for (auto& p : recursive_directory_iterator(switchAlbumPath))   // iterate through all to get total files for progress
  70.     {
  71.         current = p;
  72.         string fileName = current.filename().generic_string();
  73.  
  74.         if (fileName.size() == 53) totalFiles++;
  75.     }
  76.  
  77.     for (auto& p : recursive_directory_iterator(switchAlbumPath))
  78.     {
  79.         current = p;
  80.         string fileName = current.filename().generic_string();
  81.  
  82.         if (fileName.size() == 53)  // AAAAAAAAAAAAAAAA-BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB.jpg (or .mp4)
  83.         {
  84.             string format = fileName.substr(fileName.size() - 4);
  85.             string dateInfo = fileName.substr(0, 16);
  86.             string gameID = fileName.substr(17, 32);
  87.             string gameName;
  88.             if (gameList.count(gameID) == 0)    // If game ID isn't in list
  89.             {
  90.                 cout << "Enter game name for current ID (" << gameID << "): ";
  91.                 getline(cin, gameName);
  92.                 gameList[gameID] = gameName;
  93.  
  94.                 string line = gameID + '    ' + gameName + '\n';
  95.  
  96.                 knownGamesOut.open("GameIDs.txt", std::ios::app);
  97.                 knownGamesOut << line;
  98.                 knownGamesOut.close();
  99.             }
  100.  
  101.             else gameName = gameList[gameID];
  102.  
  103.             string dir = "C:\\Test\\" + gameName;
  104.             for (int i = 0; i < dir.size(); i++) for (int ch = 0; ch < PROHIBITED_CHARACTERS.size(); ch++) if (dir[i] == ch) dir[i] = '_';
  105.  
  106.             string file = dir + "\\" + dateInfo + format;
  107.             for (int i = 0; i < file.size(); i++) for (int ch = 0; ch < PROHIBITED_CHARACTERS.size(); ch++) if (file[i] == ch) file[i] = '_';
  108.  
  109.             if (!exists(dir)) create_directories(dir);
  110.             if (!exists(file))
  111.             {
  112.                 copy(p, file);
  113.                 cout << "Copied ";
  114.             }
  115.  
  116.             else cout << "Already copied ";
  117.  
  118.             cout << currentFile << "/" << totalFiles << endl;
  119.             currentFile++;
  120.         }
  121.     }
  122.  
  123.     system("Pause");
  124. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement