How to delete a file?
-
I'm now writing a program using MFC. I plan to incorporate a file deletion feature into the program. Thank you for your help.
-
I use this function: int RecycleBin (LPCSTR File) { // sends the specified file to the recycle bin. // returns zero on success, non-zero otherwise. char buffer[MAX_PATH]; ::ZeroMemory (buffer, MAX_PATH); strcpy (buffer, File); SHFILEOPSTRUCT fos; ::ZeroMemory (&fos, sizeof (SHFILEOPSTRUCT)); fos.wFunc = FO_DELETE; fos.pFrom = buffer; fos.fFlags = FOF_NOCONFIRMATION | FOF_NOERRORUI | FOF_SILENT | FOF_ALLOWUNDO; return SHFileOperation (&fos); } ;)
-
I use this function: int RecycleBin (LPCSTR File) { // sends the specified file to the recycle bin. // returns zero on success, non-zero otherwise. char buffer[MAX_PATH]; ::ZeroMemory (buffer, MAX_PATH); strcpy (buffer, File); SHFILEOPSTRUCT fos; ::ZeroMemory (&fos, sizeof (SHFILEOPSTRUCT)); fos.wFunc = FO_DELETE; fos.pFrom = buffer; fos.fFlags = FOF_NOCONFIRMATION | FOF_NOERRORUI | FOF_SILENT | FOF_ALLOWUNDO; return SHFileOperation (&fos); } ;)
Pretty cool, I like this function a lot better than ::DeleteFile(..) I think it sucks if an application I wrote just deletes a (any) file, without leaving the user the ability to un-delete it. Although I'd understand you use DeleteFile if your application only write a temporary file (e.g. a spoolfile or whatever) to the 'Temp'-folder. No need to recycle that one. -- Alex Marbus
-
I'm now writing a program using MFC. I plan to incorporate a file deletion feature into the program. Thank you for your help.