Hi guys,
This is my first time trying to implement something using the Windows API... I want to send a file to Trash on Windows. I searched the internet and found a couple more or less helpful pages, and I eventually ended up with the following couple lines of code:
QString filepath
= "C:\\some\\file";
if(!f.exists())
qDebug() << "ERROR: File doesn't exist";
SHFILEOPSTRUCT FileOPStruct;
filepath += '\0';
FileOPStruct.hwnd=NULL;
FileOPStruct.wFunc=FO_DELETE;
FileOPStruct.pFrom=LPCWSTR(filepath.toStdString().c_str());
FileOPStruct.pTo=NULL;
FileOPStruct.fFlags=FOF_NOCONFIRMATION | FOF_NOERRORUI | FOF_ALLOWUNDO | FOF_SILENT;
FileOPStruct.hNameMappings=NULL;
FileOPStruct.lpszProgressTitle=NULL;
if(SHFileOperation(&FileOPStruct))
qDebug() << "ERROR: Deletion failed";
else
qDebug() << "Deleted :)";
QString filepath = "C:\\some\\file";
QFile f(filepath);
if(!f.exists())
qDebug() << "ERROR: File doesn't exist";
SHFILEOPSTRUCT FileOPStruct;
filepath += '\0';
FileOPStruct.hwnd=NULL;
FileOPStruct.wFunc=FO_DELETE;
FileOPStruct.pFrom=LPCWSTR(filepath.toStdString().c_str());
FileOPStruct.pTo=NULL;
FileOPStruct.fFlags=FOF_NOCONFIRMATION | FOF_NOERRORUI | FOF_ALLOWUNDO | FOF_SILENT;
FileOPStruct.hNameMappings=NULL;
FileOPStruct.lpszProgressTitle=NULL;
if(SHFileOperation(&FileOPStruct))
qDebug() << "ERROR: Deletion failed";
else
qDebug() << "Deleted :)";
To copy to clipboard, switch view to plain text mode
The file in QString filepath exists (the check passes just fine), but I always get to "ERROR: Deletion failed", and the file (obviously) is still there. I don't have any previous experience of using the Win API and am just not able to resolve the issue... would anyone mind helping me?
Thanks a million!! :-)
Bookmarks