ScrapExplorer - blkrn.cpp

Home / usr / blkrn Lines: 9 | Size: 3725 bytes [Download] [Show on GitHub] [Search similar files] [Raw] [Raw (proxy)]
[FILE BEGIN]
1/* BLK-RN 2 * A lightweight bulk rename tool for Linux 3 * Github: https://www.github.com/0x4248/blk-rn 4 * Licence: GNU General Public License v3.0 5 * By: 0x4248 6 */ 7 8#include <filesystem> 9#include <iostream> 10#include <string.h> 11 12#define RED "\033[31m" 13#define GREEN "\033[32m" 14#define BLUE "\033[34m" 15#define CYAN "\033[36m" 16#define WHITE "\033[37m" 17 18#define BANNER \ 19 " ****** ** ** ** ******* **** **\n" \ 20 "/*////** /** /** ** /**////** /**/** /**\n" \ 21 "/* /** /** /** ** /** /** /**//** /**\n" \ 22 "/****** /** /**** /******* /** //** /**\n" \ 23 "/*//// **/** /**/** /**///** /** //**/**\n" \ 24 "/* /**/** /**//** /** //** /** //****\n" \ 25 "/******* /********/** //** *****/** //**/** //***\n" \ 26 "/////// //////// // // ///// // // // /// \n" 27 28int verbose = false; 29 30void log(std::string msg) { 31 if (verbose) { 32 std::cout << "[" << BLUE << "*" << WHITE << "] " << msg << std::endl; 33 } 34} 35namespace fs = std::filesystem; 36 37int main(int argc, char *argv[]) { 38 bool quiet = false; 39 for (int i = 0; i < argc; i++) { 40 if (strcmp(argv[i], "-q") == 0) { 41 quiet = true; 42 } 43 if (strcmp(argv[i], "-v") == 0) { 44 verbose = true; 45 log("Verbose mode enabled"); 46 } 47 } 48 if (!quiet) { 49 std::cout << CYAN << BANNER << WHITE << std::endl; 50 std::cout << "Enter the path of the files to rename> "; 51 } else { 52 std::cout << "path> "; 53 } 54 std::string path; 55 std::cin >> path; 56 log("Checking if the path is valid"); 57 if (!fs::exists(path)) { 58 std::cout << "[" << RED << "X" << WHITE << "] " 59 << "The path is not valid" << std::endl; 60 return 1; 61 } 62 log("The path is valid"); 63 fs::current_path(path); 64 log("The current path is now: " + fs::current_path().string()); 65 std::string a; 66 std::string b; 67 if (!quiet) { 68 std::cout 69 << "Files will be named in order like this: 1.txt, 2.txt, 3.txt"; 70 std::cout << "You need to enter two things a and b where a is the text " 71 "before the number and b is the end of the file name and " 72 "the extension" 73 << std::endl; 74 std::cout << "For example if you have a = 'text_' and b = '.txt' then " 75 "the files will be named like this: text_1.txt, " 76 "text_2.txt, text_3.txt" 77 << std::endl; 78 std::cout << "Enter a> "; 79 std::cin >> a; 80 std::cout << "Enter b> "; 81 std::cin >> b; 82 } else { 83 std::cout << "a> "; 84 std::cin >> a; 85 std::cout << "b> "; 86 std::cin >> b; 87 } 88 int i = 1; 89 for (const auto &entry : fs::directory_iterator(fs::current_path())) { 90 log("Creating new file name"); 91 std::string new_file_name = a.c_str() + std::to_string(i) + b.c_str(); 92 log("Renaming file: " + entry.path().string()); 93 fs::rename(entry.path(), new_file_name); 94 log("Renamed file: " + entry.path().string() + " to " + new_file_name); 95 i = i + 1; 96 if (!quiet) { 97 std::cout << "[" << GREEN << "+" << WHITE << "] " 98 << "Renamed file " << entry.path() << " to " 99 << new_file_name << std::endl; 100 } 101 } 102 103 log("Done renaming files, freeing memory and exiting"); 104 path.clear(); 105 a.clear(); 106 b.clear(); 107 return 0; 108}
[FILE END]
(C) 2025 0x4248 (C) 2025 4248 Media and 4248 Systems, All part of 0x4248 See LICENCE files for more information. Not all files are by 0x4248 always check Licencing.