删除指定文件夹下小于指定大小的全部文件

<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);
}


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值