void DeleteFile (string &path)//path为绝对路径
{
string DirName = path ;
string Dot1(".");
string Dot2("..");
WIN32_FIND_DATA FindData ;//文件搜索结构
HANDLE Find ;//句柄
string DirFindName = DirName+"\\*.*";
Find = FindFirstFile(DirFindName.c_str() ,
&FindData);
FindNextFile(Find,&FindData);
if ( Find == INVALID_HANDLE_VALUE )//无效句柄
{
FindClose(Find);
cout
<<"无效句柄"<<endl;
exit( 0
);
}
while (1)
{
if
(!FindNextFile(Find,&FindData))//搜索下一个文件
break;
//string strTmpName = DirName +
FindData.cFileName ;
if ( Dot1 != FindData.cFileName
|| Dot2 != FindData.cFileName )
{
if (
FindData.dwFileAttributes == 16 )//找到的是文件夹
{
string
NewDirName = DirName + "\\" + FindData.cFileName + "\\" ;
DeleteFile(NewDirName);//递归查找
}
}
string strImg = DirName + "\\"
+ FindData.cFileName ;
string dele = "del " + strImg
;
system(dele.c_str()) ;
}
FindClose(Find);
RemoveDirectory(path.c_str());
}
|