SHFILEOPSTRUCT fp; ZeroMemory(&fp, sizeof(fp)); // MSDN: Use only fully-qualified path names. Using relative path names will have unpredictable results. // Ahh it would connect to NASA and then ... NOT!
char fname[] = "c:\\somwhere\\filename.txt\0"; // Double null terminated fp.wFunc = FO_DELETE; fp.pFrom = (LPCSTR)fname; fp.pTo = "\0"; // Double null terminated
// Delete it silently without any confimations or errors (if occur). fp.fFlags = FOF_ALLOWUNDO | FOF_NOCONFIRMATION | FOF_NOERRORUI; if (SHFileOperation(&fp) != 0) { MessageBox(0, "File was NOT deleted!", "Error", 0); } else MessageBox(0, "File was moved to Recycle-Bin!", "Error", 0); |