Delete directory and its content to recycle bin

Hi,

I have this code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
static bool deleteDirectory(string lpszDir, bool noRecycleBin = false)
{
	int len = lpszDir.length();
	TCHAR* pszFrom = new TCHAR[len + 4]; //4 to handle wide char
	//_tcscpy(pszFrom, lpszDir); //todo:remove warning//;//convet wchar to char*
	memcpy(pszFrom, lpszDir.c_str(), len + 2);
	pszFrom[len] = 0;
	pszFrom[len + 1] = 0;

	SHFILEOPSTRUCT fileop;
	fileop.hwnd = NULL;    // no status display
	fileop.wFunc = FO_DELETE;  // delete operation
	fileop.pFrom = pszFrom;  // source file name as double null terminated string
	fileop.pTo = NULL;    // no destination needed
	fileop.fFlags = FOF_NOCONFIRMATION | FOF_SILENT;  // do not prompt the user

	if (!noRecycleBin)
		fileop.fFlags |= FOF_ALLOWUNDO;

	fileop.fAnyOperationsAborted = FALSE;
	fileop.lpszProgressTitle = NULL;
	fileop.hNameMappings = NULL;

	int ret = SHFileOperation(&fileop); //SHFileOperation returns zero if successful; otherwise nonzero 
	delete[] pszFrom;
	return (0 == ret);
}


It works great, but, it deletes only the sub folders of the directory and their content. I want it to delete the main directory and its sub-directory/files to recycle bin.

What need to be changed in the code?
Last edited on
Topic archived. No new replies allowed.