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

来源:互联网 发布:python exec函数 编辑:程序博客网 时间:2024/05/14 06:25
<img src="http://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 hereUpdateData(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 hereCString 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 hereUpdateData(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 0
原创粉丝点击