删除文件至回收站而不是永久删除

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!
 }

你可能感兴趣的:(文件)