Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Писал приложение под себя. Нужно было очистить файлы с заданиями для учеников от рабочего кода,
- оставляя только условие задач.
- Требует С++15
- */
- #include <iostream>
- #include <fstream>
- #include <string>
- #include <filesystem>
- int main() {
- std::string delimiter = " // // // // // // // Solution // // // // // // //";
- // Получаем текущую директорию
- std::filesystem::path currentDir = std::filesystem::current_path();
- // Создаем папку "clean solution" в текущей директории, если она не существует
- std::filesystem::path cleanDir = currentDir / "clean solution";
- if (!std::filesystem::exists(cleanDir)) {
- std::filesystem::create_directory(cleanDir);
- }
- // Проходим по всем файлам с расширением ".cpp" в текущей директории
- for (const auto& entry : std::filesystem::directory_iterator(currentDir)) {
- if (entry.path().extension() == ".cpp") {
- std::ifstream inputFile(entry.path());
- std::ofstream outputFile(cleanDir / entry.path().filename());
- bool write = true;
- std::string line;
- while (std::getline(inputFile, line)) {
- if (line.find(delimiter) != std::string::npos) {
- write = false;
- }
- if (write) {
- outputFile << line << '\n';
- }
- }
- }
- }
- std::cout << "Cleaning and saving completed." << std::endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement