![]() |
How to send files to the system Recycle Bin
When you want to have more advanced options, such as to throw away the
files into the system Recycle Bin, or to remove directories, you will
find that the
If you want to delete directores or send files to Recycle Bin, you can
explore this In fact, the function is not that hard to use. First of all, the file name must be supplied to the function. This part is not too much of a problem for an experienced C user, but can be tricky if not. Multiple files can be specified, and the file names must be separated by a null. And the file name variable must be terminated with double null's.
Then set other options in
Call |
void SendFileToRecycleBin(CString fileName)
{
int len=fileName.GetLength();
TCHAR* buf=(TCHAR*)malloc(sizeof(TCHAR)*(len+2));
wcscpy(buf,fileName.GetBuffer());
buf[len+1]='\0';
SHFILEOPSTRUCT FileOp;
FileOp.hwnd = this->GetSafeHwnd();
FileOp.wFunc = FO_DELETE;
FileOp.pFrom =buf;
FileOp.pTo = NULL;
FileOp.fFlags = FOF_ALLOWUNDO | FOF_NOCONFIRMATION | FOF_NOERRORUI | FOF_SILENT;
FileOp.fAnyOperationsAborted = FALSE;
FileOp.hNameMappings = NULL;
FileOp.lpszProgressTitle = NULL;
SHFileOperation( &FileOp );
free(buf);
}