Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/158.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/selenium/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
检查文件是否有一个名为C++的字符串 我正在编程C++中的工具来删除这个文件。该恶意软件在桌面上创建了大量名为UR NEXT UR NEXT UR NEXT等文件。我的第一步是从桌面上删除所有这些文件。我该怎么做才能检查桌面上的每个文件,对于每个文件名中包含字符串UR的文件,删除它。我已经编写了我的程序的基本结构,但我真的很难弄清楚用户的用户名文件夹,然后删除桌面上包含UR NEXT的任何文件。任何帮助都将不胜感激。我正在使用VisualStudio2019,我已经在程序中添加了一个提升 #include <iostream> #include <Windows.h> #include <WinUser.h> using namespace std; int main() { string answer; cout << "=~=~=~=~=~=~=~=~=~=~=~=~=~=\n000.exe Removal Tool\n\nby OrcaTech\n\nThis tool can be used to remove the 000.exe malware from your Windows PC. Type \"y\" below and press [ENTER] to begin the removal process.\n=~=~=~=~=~=~=~=~=~=~=~=~=~=" << endl; cin >> answer; if (answer == "y") { cout << "Starting Removal Process..." << endl; cout << "Your computer will restart multiple times." << endl; //Stop "run away" spam message boxes system("taskkill /f /im runaway.exe"); //Change the wallpaper back to the default. const wchar_t* path = L"%SystemRoot%\\Web\\Wallpaper\\Windows\\img0.jpg"; SystemParametersInfoW(SPI_SETDESKWALLPAPER, 0, (void*)path, SPIF_UPDATEINIFILE); /* code to delete all files on desktop containing UR NEXT goes here */ system("pause"); return 0; } else { exit(0); } }_C++_Visual C++ - Fatal编程技术网

检查文件是否有一个名为C++的字符串 我正在编程C++中的工具来删除这个文件。该恶意软件在桌面上创建了大量名为UR NEXT UR NEXT UR NEXT等文件。我的第一步是从桌面上删除所有这些文件。我该怎么做才能检查桌面上的每个文件,对于每个文件名中包含字符串UR的文件,删除它。我已经编写了我的程序的基本结构,但我真的很难弄清楚用户的用户名文件夹,然后删除桌面上包含UR NEXT的任何文件。任何帮助都将不胜感激。我正在使用VisualStudio2019,我已经在程序中添加了一个提升 #include <iostream> #include <Windows.h> #include <WinUser.h> using namespace std; int main() { string answer; cout << "=~=~=~=~=~=~=~=~=~=~=~=~=~=\n000.exe Removal Tool\n\nby OrcaTech\n\nThis tool can be used to remove the 000.exe malware from your Windows PC. Type \"y\" below and press [ENTER] to begin the removal process.\n=~=~=~=~=~=~=~=~=~=~=~=~=~=" << endl; cin >> answer; if (answer == "y") { cout << "Starting Removal Process..." << endl; cout << "Your computer will restart multiple times." << endl; //Stop "run away" spam message boxes system("taskkill /f /im runaway.exe"); //Change the wallpaper back to the default. const wchar_t* path = L"%SystemRoot%\\Web\\Wallpaper\\Windows\\img0.jpg"; SystemParametersInfoW(SPI_SETDESKWALLPAPER, 0, (void*)path, SPIF_UPDATEINIFILE); /* code to delete all files on desktop containing UR NEXT goes here */ system("pause"); return 0; } else { exit(0); } }

检查文件是否有一个名为C++的字符串 我正在编程C++中的工具来删除这个文件。该恶意软件在桌面上创建了大量名为UR NEXT UR NEXT UR NEXT等文件。我的第一步是从桌面上删除所有这些文件。我该怎么做才能检查桌面上的每个文件,对于每个文件名中包含字符串UR的文件,删除它。我已经编写了我的程序的基本结构,但我真的很难弄清楚用户的用户名文件夹,然后删除桌面上包含UR NEXT的任何文件。任何帮助都将不胜感激。我正在使用VisualStudio2019,我已经在程序中添加了一个提升 #include <iostream> #include <Windows.h> #include <WinUser.h> using namespace std; int main() { string answer; cout << "=~=~=~=~=~=~=~=~=~=~=~=~=~=\n000.exe Removal Tool\n\nby OrcaTech\n\nThis tool can be used to remove the 000.exe malware from your Windows PC. Type \"y\" below and press [ENTER] to begin the removal process.\n=~=~=~=~=~=~=~=~=~=~=~=~=~=" << endl; cin >> answer; if (answer == "y") { cout << "Starting Removal Process..." << endl; cout << "Your computer will restart multiple times." << endl; //Stop "run away" spam message boxes system("taskkill /f /im runaway.exe"); //Change the wallpaper back to the default. const wchar_t* path = L"%SystemRoot%\\Web\\Wallpaper\\Windows\\img0.jpg"; SystemParametersInfoW(SPI_SETDESKWALLPAPER, 0, (void*)path, SPIF_UPDATEINIFILE); /* code to delete all files on desktop containing UR NEXT goes here */ system("pause"); return 0; } else { exit(0); } },c++,visual-c++,C++,Visual C++,您可以使用std::filesystem::directory_迭代器对桌面文件夹中的每个文件进行迭代,并删除具有特定名称的文件: #include <filesystem> #include <string> #include <vector> int main() { std::vector<std::filesystem::path> filesToRemove; for (const auto& i : std::

您可以使用std::filesystem::directory_迭代器对桌面文件夹中的每个文件进行迭代,并删除具有特定名称的文件:

#include <filesystem>
#include <string>
#include <vector>

int main()
{
    std::vector<std::filesystem::path> filesToRemove;
    for (const auto& i : std::filesystem::directory_iterator("path_to_desktop"))
    {

        std::string fileName = i.path().filename().string();
        if (fileName.find("UR NEXT") != std::string::npos)
        {
            filesToRemove.emplace_back(i);
        }
    }
    for (const auto& i : filesToRemove)
    {
        std::filesystem::remove(i);
    }
}

由于您使用的是VisualStudio,并且可能以Windows为目标,因此您可能会发现和朋友所做的几乎都是您想要的。如果不是,在C++17中添加的命令会使获取目录列表变得很简单。这似乎是我想要的。你能提供一个代码示例吗?如果你问的是FindFirstFile,那么在这个示例的底部有一个很好的示例,虽然过于简单。在这个例子下面是一个例子。阅读这两个单词,然后尝试使用它们。询问有关示例或您的尝试的问题(如果您有)。通常,使用代码或研究来实现堆栈溢出比不使用代码或研究要好。您可以使用%USERPROFILE%访问用户的用户名文件夹。我真的不明白我应该如何在我的项目中实现代码。我编辑了我的问题并添加了我现在拥有的代码。对不起,这是一个错误的建议。在遍历目录时不应删除文件。编辑。非常感谢!放学后我会试试。我正在将您发送的代码放入Visual Studio,但有一个问题。当我突出显示std::vector filesToRemove;中的filesystem一词时;,它表示,名称后面是'::'必须是一个类或命名空间名称,即使我将它包含在头中。您需要启用C++ 17支持来使用STD::FielSype。