/ *************** Delete files to the recycle station ****************************** PSZPATH: the full path file name to be deepened BDELETE: TRUE Delete, moving to the recycle bin, FALSE: Move to the recycle bin Return: True Delete Success False Delete Failed / ******************************************************************************************************************************************************************************************************************************************* ***************************** /
BOOL CDelFileToRecycleDlg :: Recycle (LPCTSTR pszPath, BOOL bDelete / * = FALSE * /) {SHFILEOPSTRUCT shDelFile; memset (& shDelFile, 0, sizeof (SHFILEOPSTRUCT)); shDelFile.fFlags | = FOF_SILENT; // no progress shDelFile.fFlags | = FOF_NOERRORUI; // Does not report the error information shdlfile.fflags | = fof_noconfirmation; // Directly delete, not confirming // Copy path to a String variable ended with double NULL TCHAR BUF [_MAX_PATH 1]; _TCSCPY (BUF, PSZPATH); // Copy path BUF [_tcslen (buf) 1] = 0; // add two NULL at the end
/ / Set the parameter of the SHFileOpstructure to prepare shdelfile.wfunc = fo_delete; // execution SHDELFILE.PFROM = BUF; // Object, that is, the directory shdelfile.pto = null; // must be set to NULL IF BDELETE) / / Determine if the passing BDelete parameter is deleted to the recycle bin {shdlfile.fflags & = ~ fof_allowundo; // Directly delete, do not enter the recycle bin} else {shdelfile.fflags | = fof_allowundo; // Delete to the recycle bin} Return ShfileOperation (& ShDelfile); // Delete}