#include <Windows.h>
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <Shlwapi.h>
using namespace std;
#pragma comment(lib,"Shlwapi.lib")
void FileDelete(char* directory)
{
SHFILEOPSTRUCT shFileOp;
memset(&shFileOp,0,sizeof(shFileOp));
char temp[MAX_PATH]={0};
strcpy(temp,directory);
shFileOp.wFunc= FO_DELETE;
shFileOp.pFrom= temp;
shFileOp.pTo= NULL;
shFileOp.fFlags= FOF_SILENT | FOF_NOCONFIRMATION | FOF_NOCONFIRMMKDIR;
if(0==SHFileOperation(&shFileOp))
cout<<directory<<" 已删除"<<endl;
}
void find(char *lpPath)
{
string strFile;
int pos;
string strFileExt;
char szFind[MAX_PATH];
char szFile[MAX_PATH];
char szDelePath[MAX_PATH];
WIN32_FIND_DATAA FindFileData;
strcpy(szFind,lpPath);
strcat(szFind,"*.*");
HANDLE hFind=::FindFirstFileA(szFind,&FindFileData);
if(INVALID_HANDLE_VALUE == hFind)
return;
while(TRUE)
{
if(FindFileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
{
if(FindFileData.cFileName[0]!='.')
{
if(strcmp(FindFileData.cFileName,"ipch")==0)
{
sprintf(szDelePath,"%sipch",lpPath);
FileDelete(szDelePath);
}else if(strcmp(FindFileData.cFileName,"Debug")==0)
{
sprintf(szDelePath,"%sDebug",lpPath);
FileDelete(szDelePath);
}else if(strcmp(FindFileData.cFileName,"Release")==0)
{
sprintf(szDelePath,"%sRelease",lpPath);
FileDelete(szDelePath);
}
//cout<<lpPath<<endl;
strcpy(szFile,lpPath);
strcat(szFile,"\\");
strcat(szFile,FindFileData.cFileName);
strcat(szFile,"\\");
find(szFile);
}
}
else
{
strFile=FindFileData.cFileName;
pos=strFile.find_last_of('.');
if(pos>0)
strFileExt=strFile.substr(pos+1);
if(strcmp("sdf",strlwr((char*)strFileExt.c_str()))==0)
{
strcpy(szFile,lpPath);
strcat(szFile,"\\");
strcat(szFile,FindFileData.cFileName);
FileDelete(szFile);
//cout<<FindFileData.cFileName<<" 已删除"<<endl;
}
}
if(!FindNextFile(hFind,&FindFileData))
break;
}
FindClose(hFind);
}
int main()
{
cout<<"************************************"<<endl;
cout<<"************************************"<<endl;
cout<<"---------->VS2010清理助手<----------"<<endl;
cout<<"************************************"<<endl;
cout<<"注意:程序会删除你所输入目录下所有.sdf文件"<<endl;
cout<<"以及名为Debug、Release、ipch文件夹"<<endl;
cout<<"使用本程序所造成的一切后果,请使用者承担"<<endl;
cout<<" By L0g1n 2012.8.4晚"<<endl;
cout<<"************************************"<<endl;
cout<<"请输入文件夹:(如E盘下所有文件E:\\)"<<endl;
char szInput[MAX_PATH];
cin>>szInput;
find(szInput);
system("pause");
return 0;
}
注:程序在使用管理员权限,否则删不掉。
今天清理了一下,瞬间多了30多个G,很好,很强大啊。