Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <string>
- #include <iostream>
- #include <fstream>
- #include <vector>
- #include <filesystem>
- namespace fs = std::experimental::filesystem;
- using namespace std; // Typing std:: before everything is messy and unnecessary for this kinda thing
- int main()
- {
- string path; // Path to series directory
- int startNumber; // The index of the first episode of a folder (eg, Attack on Titan S2E1 is actually episode 26)
- string epNumberTxt; // The current episode, including zero padding
- string seriesName; // Name of the series
- string newFileName; // The final assembled file name
- string fileExtension; // Extension of the file (can probably be grabbed automatically, might do that at some point)
- int totalEpisodes; // Used to find how many zeros to pad with
- cout << "Enter the path of your series: ";
- getline(cin, path);
- if (path[path.length() - 1] != '\\') path = path + "\\";
- cout << "Enter the series name: ";
- getline(cin, seriesName);
- cout << "Enter the video format (eg, .mkv): ";
- getline(cin, fileExtension);
- if (fileExtension[0] != '.') fileExtension = "." + fileExtension;
- cout << "Enter the number of the first episode present: ";
- cin >> startNumber;
- cout << "Enter the total number of episodes for the series: ";
- cin >> totalEpisodes;
- fstream fileNames;
- fileNames.open("Names.txt");
- vector<string> nameList;
- string line;
- while (getline(fileNames, line))
- {
- for (int i = 0; i < line.length(); i++)
- {
- if (line[i] == '\\' || // Check for prohibited characters in the new file name before applying it
- line[i] == '/' ||
- line[i] == ':' ||
- line[i] == '*' ||
- line[i] == '?' ||
- line[i] == '"' ||
- line[i] == '<' ||
- line[i] == '>' ||
- line[i] == '|')
- line[i] = '_'; // Replace with underscore
- }
- nameList.push_back(line);
- }
- int iteration = 0;
- for (auto & p : fs::directory_iterator(path)) // For each file in the directory
- {
- if (nameList.size() > iteration)
- {
- if (totalEpisodes >= 100) // If the series is 100+ episodes, 0-9 need "00", and 10-99 need "0"
- {
- if (startNumber + iteration < 10) epNumberTxt = "00" + to_string(startNumber + iteration);
- else if (startNumber + iteration < 100) epNumberTxt = "0" + to_string(startNumber + iteration);
- else epNumberTxt = to_string(startNumber + iteration);
- }
- else if (totalEpisodes >= 10) // If the series is 10+ episodes, 1-9 need "0"
- {
- if (startNumber + iteration < 10) epNumberTxt = "0" + to_string(startNumber + iteration);
- else epNumberTxt = to_string(startNumber + iteration);
- }
- newFileName = path + seriesName + " " + epNumberTxt + " - " + nameList[iteration] + fileExtension; // Assembles final file name, path is required else it'll be placed
- rename(p, newFileName.c_str()); // in the same folder as the program
- iteration++;
- }
- }
- cout << endl;
- system("Pause");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement