<img src="https://img-blog.csdn.net/20141009142553796?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvaGVpaGVpMzY=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center" alt="" />
</pre><pre class="cpp" name="code">void CdelsmallfileDlg::OnBnClickedButtonSetsize()
{
// TODO: Add your control notification handler code here
UpdateData(TRUE);
std::string strTemp = m_strSize.GetBuffer(m_strSize.GetLength());
m_strSize.ReleaseBuffer(m_strSize.GetLength());
m_nFileLength = atoi(strTemp.c_str());
}
void CdelsmallfileDlg::OnBnClickedButtonSelectpath()
{
// TODO: Add your control notification handler code here
CString sFolderPath;
BROWSEINFO bi;
TCHAR Buffer[MAX_PATH];
//初始化入口参数bi开始
bi.hwndOwner = NULL;
bi.pidlRoot =NULL;//初始化制定的root目录很不容易,
bi.pszDisplayName = Buffer;//此参数如为NULL则不能显示对话框
bi.lpszTitle = _T("选择路径");
//bi.ulFlags = BIF_BROWSEINCLUDEFILES;//包括文件
bi.ulFlags = BIF_EDITBOX;//包括文件
bi.lpfn = NULL;
bi.iImage=IDR_MAINFRAME;
//初始化入口参数bi结束
LPITEMIDLIST pIDList = SHBrowseForFolder(&bi);//调用显示选择对话框
if(pIDList)
{
SHGetPathFromIDList(pIDList, Buffer);
//取得文件夹路径到Buffer里
m_strPath = Buffer;//将路径保存在一个CString对象里
GetDlgItem(IDC_EDIT_PATH)->SetWindowText(m_strPath);
}
}
void CdelsmallfileDlg::TravelFolder(CString strDir)
{
CFileFind filefind; //声明CFileFind类型变量
CString strWildpath = strDir + _T("//*.*"); //所有文件都列出。
if(filefind.FindFile(strWildpath, 0)) //开始检索文件
{
BOOL bRet = TRUE;
while(bRet)
{
bRet = filefind.FindNextFile(); //枚举一个文件
if(filefind.IsDots()) //如果是. 或 .. 做下一个
continue;
if(!filefind.IsDirectory()) //不是子目录,把文件名打印出来
{
CString strTextOut = strDir + CString(_T("//")) + filefind.GetFileName();
//TRACE(_T("file = %s/r/n"), strTextOut);
int nFileLength = filefind.GetLength();
if ( nFileLength < m_nFileLength )
{
DeleteFile(strTextOut);
m_EditFileName.SetWindowText( _T("Delete File ") + strTextOut + _T("...") );
}
}
else //如果是子目录,递归调用该函数
{
CString strTextOut = strDir + CString(_T("//")) + filefind.GetFileName();
TRACE(_T("dir = %s/r/n"), strTextOut);
TravelFolder(strTextOut);//递归调用该函数打印子目录里的文件
}
}
filefind.Close();
}
}
void CdelsmallfileDlg::OnBnClickedButtonRun()
{
// TODO: Add your control notification handler code here
UpdateData(TRUE);
std::string strTemp = m_strSize.GetBuffer(m_strSize.GetLength());
m_strSize.ReleaseBuffer(m_strSize.GetLength());
m_nFileLength = atoi(strTemp.c_str());
m_nFileLength *= 1024;
GetDlgItem(IDC_EDIT_PATH)->GetWindowText(m_strPath);
TravelFolder(m_strPath);
}