My test function simply performs:
SHFILEOPSTRUCT shfos;
ZeroMemory(&shfos, sizeof(shfos));
char buffer[1024] = {"C:\\emacs\\etc\\CVS\\\0"};
shfos.wFunc = FO_DELETE;
shfos.pFrom = buffer;
shfos.fFlags = FOF_ALLOWUNDO;
int ret = SHFileOperation(&shfos);
if (ret != 0)
MessageBox(NULL, "Error", "Error", MB_OK);
Any ideas?
/ E
This one seems to do the trick nicely:
#include <windows.h>
#include <iostream>
#include <string.h>
int main()
{
SHFILEOPSTRUCT shfos;
memset(&shfos, 0, sizeof(shfos));
char buffer[1024] = {"C:\\T"};
shfos.wFunc = FO_DELETE;
shfos.pFrom = buffer;
shfos.fFlags = FOF_ALLOWUNDO | FOF_SILENT | FOF_NOCONFIRMATION;
int ret = SHFileOperation(&shfos);
if (ret != 0)
std::cout << "Error: " << GetLastError() << std::endl;
}
Are you sure that no one has links to the file in the folder
when you try to remove it?
Can you remove the folder by hand?
--
Just another homepage:
http://damb.dk
But it's mine - Bertel
Yes, I can without. No problem there. Hmm.
SHFILEOPSTRUCT fo;
char path[256] = "C:\\Folder\\:
char name[128] = "nameOfFile.wtf";
strcat ( path, name );
fo.hwnd = hMainWnd; //puts any messageboxes on top
fo.wFunc = FO_DELETE;
fo.fFlags = FOF_ALLOWUNDO;
fo.pFrom = path;
fo.pTo = "Recycle Bin";
SHFileOperation ( &fo );
if ( fAnyOperationsAborted == FALSE )
{ ResetList ( " or whatever " ); }
The pathname has to be fully qualified and (of course) correct.
Filenames taken from listboxes and textfiles have newline
markers attached to the end of the filename. \0 \n \r \t...
Try StrTrim ( name, " \0 " ); StrTrim ( name," \n ");
StrTrim ( name," \r "); StrTrim ( name, " " );
For me , SHFileOperation fails for2 reasons. Incorrect path and
filename and ' Read-Only' files.
See the below blog entries:
Chris