staticbool 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.