-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
109 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
#include "shlobj.h" | ||
#include "string" | ||
using namespace std; | ||
|
||
int main() { | ||
//获取桌面路径 | ||
LPITEMIDLIST pidl; | ||
LPMALLOC pShellMalloc; | ||
char szDir[200]; | ||
string desktop; | ||
if (SUCCEEDED(SHGetMalloc(&pShellMalloc))) { | ||
if (SUCCEEDED(SHGetSpecialFolderLocation(NULL, CSIDL_DESKTOP, &pidl))) { | ||
// 如果成功返回true | ||
SHGetPathFromIDListA(pidl, szDir); | ||
pShellMalloc->Free(pidl); | ||
} | ||
pShellMalloc->Release(); | ||
} | ||
desktop = string(szDir); | ||
strcat(szDir, "\\*"); | ||
|
||
//遍历文件夹 | ||
WIN32_FIND_DATAA fileInfo; | ||
HANDLE hFile = FindFirstFileA(szDir, &fileInfo); | ||
|
||
if (hFile == INVALID_HANDLE_VALUE) { | ||
return -1; | ||
} | ||
|
||
do { | ||
//如果是文件夹 | ||
if (fileInfo.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) { | ||
char oldname[200]; | ||
char newname[200]; | ||
string pt = ".{20D04FE0-3AEA-1069-A2D8-08002B30309D}"; | ||
//是否已经修改 | ||
if (string(fileInfo.cFileName).find(pt) != string::npos ) { | ||
printf("no need!\n"); | ||
continue; | ||
} | ||
strcpy(oldname, (desktop + "\\" + fileInfo.cFileName).c_str()); | ||
strcpy(newname, (desktop + "\\" + fileInfo.cFileName + pt).c_str()); | ||
printf("%s\n", newname); | ||
//重命名 | ||
if (rename(oldname, newname) == 0) | ||
printf("修改成功\n"); | ||
else | ||
perror("rename"); | ||
} | ||
} while (FindNextFileA(hFile, &fileInfo)); | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
#include "shlobj.h" | ||
#include "string" | ||
using namespace std; | ||
|
||
int main() { | ||
//获取桌面路径 | ||
LPITEMIDLIST pidl; | ||
LPMALLOC pShellMalloc; | ||
char szDir[200]; | ||
string desktop; | ||
if (SUCCEEDED(SHGetMalloc(&pShellMalloc))) { | ||
if (SUCCEEDED(SHGetSpecialFolderLocation(NULL, CSIDL_DESKTOP, &pidl))) { | ||
// 如果成功返回true | ||
SHGetPathFromIDListA(pidl, szDir); | ||
pShellMalloc->Free(pidl); | ||
} | ||
pShellMalloc->Release(); | ||
} | ||
desktop = string(szDir); | ||
strcat(szDir, "\\*"); | ||
|
||
//遍历文件夹 | ||
WIN32_FIND_DATAA fileInfo; | ||
HANDLE hFile = FindFirstFileA(szDir, &fileInfo); | ||
|
||
if (hFile == INVALID_HANDLE_VALUE) { | ||
return -1; | ||
} | ||
|
||
do { | ||
//如果是文件夹 | ||
if (fileInfo.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) { | ||
char oldname[200]; | ||
char newname[200]; | ||
string pt = ".{20D04FE0-3AEA-1069-A2D8-08002B30309D}"; | ||
//是否需要修复 | ||
if (string(fileInfo.cFileName).find(pt) == string::npos ) { | ||
printf("no need!\n"); | ||
continue; | ||
} | ||
strcpy(oldname, (desktop + "\\" + fileInfo.cFileName).c_str()); | ||
//截去后缀 | ||
int length = string(fileInfo.cFileName).length() - pt.length(); | ||
string t = string(fileInfo.cFileName).substr(0, length); | ||
strcpy(newname, (desktop + "\\" + t).c_str()); | ||
|
||
printf("%s\n", oldname); | ||
//重命名 | ||
if (rename(oldname, newname) == 0) | ||
printf("修改成功\n"); | ||
else | ||
perror("rename"); | ||
} | ||
|
||
} while (FindNextFileA(hFile, &fileInfo)); | ||
return 0; | ||
} |