ردود الذكاء الاصطناعي
سؤالك:
إجابة الشبكة العصبية:
#include <iostream> #include <string> #include <io.h>
void searchWordInDirectory(const std::string& path, const std::string& word) { struct _finddata_t fileinfo; intptr_t handle; std::string searchPath = path + "\.";
handle = _findfirst(searchPath.c_str(), &fileinfo);
if (handle == -1) {
std::cout << "Error searching directory: " << path << std::endl;
return;
}
do {
if (fileinfo.attrib & _A_SUBDIR) {
if (strcmp(fileinfo.name, ".") != 0 && strcmp(fileinfo.name, "..") != 0) {
std::string subdir = path + "\\" + fileinfo.name;
searchWordInDirectory(subdir, word);
}
} else {
std::string filePath = path + "\\" + fileinfo.name;
FILE* file = fopen(filePath.c_str(), "r");
if (file) {
char buffer[1024];
int count = 0;
while (fgets(buffer, sizeof(buffer), file)) {
if (strstr(buffer, word.c_str())) {
count++;
}
}
if (count > 0) {
std::cout << "Word '" << word << "' found in file: " << filePath << " - " << count << " occurrences" << std::endl;
}
fclose(file);
}
}
} while (_findnext(handle, &fileinfo) == 0);
_findclose(handle);
}
void replaceWordInDirectory(const std::string& path, const std::string& word, const std::string& replacement) { // TODO: Implement word replacement in files }
int main() { std::string path, word; std::cout << "Enter directory path: "; std::cin >> path; std::cout << "Enter word to search: "; std::cin >> word;
searchWordInDirectory(path, word);
// Replace word in files
std::string replacement;
std::cout << "Enter word to replace with: ";
std::cin >> replacement;
replaceWordInDirectory(path, word, replacement);
return 0;
}
يرجى ملاحظة: قد لا تكون الإجابات المقدمة بواسطة الذكاء الاصطناعي دقيقة دائمًا. لا تعتمد عليها في القضايا الحساسة مثل الطب، القانون، الأمور المالية أو القضايا الأمنية. من الأفضل دائمًا الرجوع إلى المتخصصين المؤهلين عند اتخاذ القرارات المهمة. إدارة الموقع غير مسؤولة عن المحتوى الذي يتم إنتاجه تلقائيًا.