I am having a simple problem that I cannot find a simple solution to. I am trying to delete a file permanently. I’m not looking for the fanciest way to make the data unrecoverable, I just don’t want it sitting in the Recycle Bin. I have two questions.
-
Is the a way to get the path to the Recycle Bin? The idea is that once I have the path I can use
remove()to delete it permanently from there. The following fails for me, returning a completely different path that isn’t that of the Recycle Bin. Maybe I am missing an argument.char RecycleBin[_MAX_PATH]; SHGetSpecialFolderPath(NULL, RecycleBin, CSIDL_BITBUCKET, FALSE); -
Is there a win32api call to permanently delete a file?
Thanks for reading.
EDIT 1:
Per the answer below, I have been using the _unlink () function but it’s behavior doesn’t do exactly what I want it to do. I need something to get the Desktop, then add a file to that string and pass the string into a function that will delete the file as an argument. Here is how I am trying with unlink.If I do unlink like this – it works:
char path [] = "C:\\Users\\testuser\\Desktop\\test.dat";
_unlink( path );
However, if I try it in the two following ways it fails.
char DesktopPath[_MAX_PATH];
SHGetSpecialFolderPath(NULL, DesktopPath, CSIDL_DESKTOPDIRECTORY, FALSE);
strcat ( DesktopPath, "\\test.dat" );
_unlink ( DesktopPath );
This way (adding quotes) also fails.
char DesktopPath[_MAX_PATH];
char final_path [] = "\"";
char quotes [] = "\"";
SHGetSpecialFolderPath(NULL, DesktopPath, CSIDL_DESKTOPDIRECTORY, FALSE);
strcat ( DesktopPath, "\\test.dat" );
strcat ( DesktopPath, quotes );
strcat ( final_path, DesktopPath );
_unlink ( final_path );
Both of the above ways compile and run fine, but it doesn’t actually get rid of the file. Any ideas?
Use the POSIX function unlink (_unlink for MSVC2005+).