int DeleteAFolder(CString & csPath)
{
// 测试删除F:\lpc
_wfinddata_t findData;
int nRes = _wfindfirst(csPath+CString(_T("\\*.*")), &findData);
int handle = nRes;
while(true)
{
if( -1 == nRes )
{
#ifdef _DEBUG
::OutputDebugString(_T("找不到相应文件\n"));
#endif
if( -1 != handle )
_findclose(handle);
break;
}
#ifdef _DEBUG
::OutputDebugString(findData.name);
::OutputDebugString(_T("\n"));
CString cst;
cst.Format(_T("unsigned:%d, size:%d, time1:%d, time2:%d, time3:%d"),
findData.attrib, findData.size, findData.time_access, findData.time_create, findData.time_write);
::OutputDebugString(cst);
::OutputDebugString(_T("\n"));
#endif
if( 0 != findData.size )
DeleteFile(csPath+CString(_T("\\"))+findData.name);
else if( 0 != (wcscmp( _T("."), findData.name)) && 0 != (wcscmp(_T(".."), findData.name)))
DeleteAFolder( csPath + CString(_T("\\")) + findData.name );
nRes = _wfindnext(handle, &findData);
}
if( 0 == RemoveDirectory(csPath))
{
#ifdef _DEBUG
int k = GetLastError();
CString csts;
csts.Format(_T("error:%d\n"),k);
::OutputDebugString(csts);
#endif
}
return 0;
}
评论