posts - 34,  comments - 5,  trackbacks - 0

class CRecycleFile : private SHFILEOPSTRUCT
{
public:
      CRecycleFile()
      {
            memset((SHFILEOPSTRUCT*)this,0,sizeof(SHFILEOPSTRUCT));
            fFlags |= FOF_SILENT;                // don't report progress
            fFlags |= FOF_NOERRORUI;             // don't report errors
            fFlags |= FOF_NOCONFIRMATION;        // don't confirm delete
      }

      ~CRecycleFile() 
      {
      }

      //
      // Send a file to the recycle bin. Args:
      //  - full pathname of file.
      //  - bDelete: if TRUE, really delete file (no recycle bin)
      //
      int Recycle(LPCTSTR pszPath, BOOL bDelete=FALSE)
      {
            TCHAR buf[_MAX_PATH + 1]; // allow one more character
            _tcscpy(buf, pszPath);    // copy caller's path name
            buf[_tcslen(buf)+1]=0;    // need two NULLs at end

            // Set SHFILEOPSTRUCT params for delete operation
            wFunc = FO_DELETE;                   // REQUIRED: delete operation
            pFrom = buf;                         // REQUIRED: which file(s)
            pTo = NULL;                          // MUST be NULL
            if(bDelete) 
            {                       // if delete requested..
                  fFlags &= ~FOF_ALLOWUNDO;         // ..don't use Recycle Bin
            } 
            else 
            {                             // otherwise..
                  fFlags |= FOF_ALLOWUNDO;          // ..send to Recycle Bin
            }
            return SHFileOperation(this);        // do it!
      }

}

posted on 2007-09-10 12:20 披星戴月 阅读(713) 评论(0)  编辑 收藏 引用 所属分类: Win32

只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理


<2007年4月>
25262728293031
1234567
891011121314
15161718192021
22232425262728
293012345

常用链接

留言簿(2)

随笔分类

随笔档案

文章档案

相册

搜索

  •  

最新评论

阅读排行榜

评论排行榜