Исправь ошибки в коде: error C2065: “: необъявленный идентификатор error C2065:…
- User
Исправь ошибки в коде: error C2065: “: необъявленный идентификатор error C2065: directory”: необъявленный идентификатор error C2065: вирусом: необъявленный идентификатор error C2065: является: необъявленный идентификатор error C2065: “Файл: необъявленный идентификатор error C2065: ”: необъявленный идентификатор
#include #include #include <dirent.h> #include #include #include
using namespace std;
bool isVirus(string fileName, string databaseFilePath) { // Открываем файл и считываем его содержимое в буфер ifstream file(fileName); string buffer((istreambuf_iterator(file)), istreambuf_iterator());
// Получаем список вирусов из базы данных ifstream databaseFile(databaseFilePath); vector<string> virusList; string line; while (getline(databaseFile, line)) { virusList.push_back(line); } // Сравниваем содержимое файла с базой данных вирусов for (string virus : virusList) { if (buffer == virus) { return true; } } return false;}
bool deleteFile(string fileName) { if (remove(fileName.c_str()) != 0) { return false; }
return true;}
vector getFilesInDirectory(string path) { vector files;
DIR* dir; struct dirent* ent; if ((dir = opendir(path.c_str())) != NULL) { while ((ent = readdir(dir)) != NULL) { if (ent->d_type == DT_REG) { // Только обычные файлы files.push_back(ent->d_name); } } closedir(dir); } return files;}
void scanDirectory(string path, string databaseFilePath) { vector files = getFilesInDirectory(path);
for (string fileName : files) { string fullFilePath = path + “ / ” + fileName; if (isVirus(fullFilePath, databaseFilePath)) { cout << “Файл " << fullFilePath << " является вирусом!” << endl; // Предлагаем удалить файл deleteFile(fullFilePath); } } // Рекурсивный вызов для всех поддиректорий DIR* dir; struct dirent* ent; if ((dir = opendir(path.c_str())) != NULL) { while ((ent = readdir(dir)) != NULL) { if (ent->d_type == DT_DIR && strcmp(ent->d_name, “.”) != 0 && strcmp(ent->d_name, “…”) != 0) { // Только директории, кроме . и … string subDirPath = path + “ / ” + ent->d_name; scanDirectory(subDirPath, databaseFilePath); } } closedir(dir); }}
int main() { // Путь к директории, которую нужно просканировать string path = “ / path / to / my / directory”;
// Путь к файлу базы данных вирусов string databaseFilePath = “ / path / to / my / database.txt”; // Сканируем директорию на наличие вирусов scanDirectory(path, databaseFilePath); return 0;}
- Assistant
#include #include #include <dirent.h> #include #include #include