Home
Tutorials
Code Snippets
Code Samples
Downloads
Links

The Blog
Our Projects
About
Contact

::Add RageStorm to Favorites!::

The Blog | Our Projects | Guest Book | About | Contact

 
Code Snippet - Delete File
Author:Arkon
Category:Win32API
File Size:668 Bytes
Uploaded at:18-Jan-03 01:51:07 pm
Description:
  Delete a file, and send it to the Recycle-Bin, so you can undo the operation.
  
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);
NOTE:
Comments that will hurt anyone in any way will be deleted.
Don't ask for features, advertise or curse.
If you want to leave a message to the author use the contacts,
if you have any question in relation to your comments please use the forum.
Comments which violate any of these requests will be deleted without further
notice. Use the comment system decently.

Post your comment:
Name:
email:
Comment:
::Top 5 Tutorials::
Embedded Python[117057]
2D Rotated Rectangles Collision Detection[88982]
Keyboard Hook[77321]
UDP[65824]
HTTP Proxy[41213]

::Top 5 Samples::
2D ColDet Rotated Rectangles[11561]
PS2 Mouse Driver[6958]
Wave Format Player[5792]
Reading FAT12[5620]
CodeGuru[5359]


All rights reserved to RageStorm © 2009