| 12
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
 100
 101
 102
 103
 104
 105
 106
 107
 108
 109
 110
 111
 112
 113
 114
 115
 116
 117
 118
 119
 120
 121
 122
 123
 124
 125
 126
 127
 128
 129
 
 | #include <iostream>#include <vector>
 #include <string>
 #include <windows.h>
 #include <winbase.h>
 #include <WinUser.h>
 #include <strsafe.h>
 #include <ShObjIdl.h>
 #include <cstring>
 #include <shlobj.h>
 #include <comutil.h>
 #include <io.h>
 #pragma comment(lib, "comsuppw.lib")
 #pragma comment(linker, "/entry:mainCRTStartup")
 
 
 bool _SetFileRebootDelete(const std::string& file_path) {
 if (MoveFileExA(file_path.c_str(), 0, MOVEFILE_DELAY_UNTIL_REBOOT)) {
 return true;
 }
 else {
 return false;
 }
 }
 
 void getFiles(std::string path, std::vector<std::string>& files, std::vector<std::string>& names)
 {
 
 long hFile = 0;
 
 struct _finddata_t fileinfo;
 std::string p;
 if ((hFile = _findfirst(p.assign(path).append("\\*").c_str(), &fileinfo)) != -1)
 {
 do
 {
 
 if ((fileinfo.attrib & _A_SUBDIR))
 {
 if (strcmp(fileinfo.name, ".") != 0 && strcmp(fileinfo.name, "..") != 0)
 {
 getFiles(p.assign(path).append("\\").append(fileinfo.name), files, names);
 }
 }
 else
 {
 files.push_back(p.assign(path).append("\\").append(fileinfo.name));
 names.push_back(fileinfo.name);
 }
 } while (_findnext(hFile, &fileinfo) == 0);
 _findclose(hFile);
 }
 }
 
 
 std::string GetLoactionDir()
 {
 DWORD dwLen = 0;
 CHAR szAppDataDir[MAX_PATH];
 dwLen = ExpandEnvironmentStringsA("%programdata%", szAppDataDir, MAX_PATH);
 
 if (dwLen != 0) {
 StringCchCatA(szAppDataDir, sizeof(szAppDataDir), ("\\TrustAgent\\logs"));
 }
 
 return szAppDataDir;
 }
 
 int GetWithRegex() {
 
 WIN32_FIND_DATAA findData;
 HANDLE hFind = INVALID_HANDLE_VALUE;
 LPCSTR lpPath = "D:\\Documents\\B_Tools\\";
 LPCSTR lpPattern = "*.7z";
 
 char buffer_1[MAX_PATH] = "";
 char* lpStr1;
 lpStr1 = buffer_1;
 
 PathCombineA(lpStr1, lpPath, lpPattern);
 
 
 hFind = FindFirstFileA(lpStr1, &findData);
 if (hFind == INVALID_HANDLE_VALUE) {
 std::cout << "FindFirstFile failed with error: " << GetLastError() << std::endl;
 return 1;
 }
 
 
 do {
 std::cout << findData.cFileName << std::endl;
 } while (FindNextFileA(hFind, &findData));
 
 
 FindClose(hFind);
 
 return 0;
 }
 
 int main()
 {
 using namespace std;
 std::string filepath = GetLoactionDir();
 
 vector<string> files;
 vector<string> names;
 
 getFiles(filepath, files, names);
 for (int i = 0; i < files.size(); i++)
 {
 printf("-----========files:%d========---\n", i);
 
 
 
 
 cout << "lnkPath: " << files[i] << endl;
 
 
 
 
 
 
 _SetFileRebootDelete(files[i]);
 }
 
 
 return 0;
 }
 
 
 |