views:

376

answers:

2

I am programing under C++, MFC, windows.

I want to delete a folder into recycle bin. How can I do this?

 CString filePath = directorytoBeDeletePath;
 TCHAR ToBuf[MAX_PATH + 10];
 TCHAR FromBuf[MAX_PATH + 10];
 ZeroMemory(ToBuf, sizeof(ToBuf));
 ZeroMemory(FromBuf, sizeof(FromBuf));

 lstrcpy(FromBuf, filePath);

 SHFILEOPSTRUCT FileOp;
 FileOp.hwnd = NULL
 FileOp.wFunc=FO_DELETE; 
 FileOp.pFrom=FromBuf;
 FileOp.pTo = NULL;
 FileOp.fFlags=FOF_ALLOWUNDO|FOF_NOCONFIRMATION;
 FileOp.hNameMappings=NULL;
 bRet=SHFileOperation(&FileOp);

Any thing wrong with the code above? It always failed.

Thanks!

I found the problem: filePath should be : "c:\abc" not "c:\abc\"

+3  A: 

The return value from SHFileOperation is an int, and should specify the error code. What do you get?

On Freund
A: 

i know it is not the right way but if you cant find a solution you can try this..

download file nircmd.exe or another exe that can empty recycle bin.

then you call these functions by system("nircmd.exe emptybin")

ufukgun
Thanks very much ~~~~