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
披星戴月 阅读(722)
评论(0) 编辑 收藏 引用 所属分类:
Win32