Datei löschen mit Standard Explorer Abfrage?
-
-
bool delete_file(const string& filename)
{SHFILEOPSTRUCT fop;
char str1[128];
int i;i = 0;
while (filename[i])
{
str1[i] = filename[i];
i++;
}
str1[i] = '\0'; ++i; // add an annoying \0 to the end of the string
str1[i] = '\0'; // the final one for the C string// initialize all data required for the copy
fop.hwnd = NULL;
fop.wFunc = FO_DELETE;
fop.pFrom = str1;
fop.pTo = NULL;
fop.fFlags = FOF_NOCONFIRMATION|FOF_SILENT;
fop.hNameMappings = NULL;
fop.lpszProgressTitle = NULL;// remaining entries are output variables, no need to initialize
SHFileOperation(&fop);
return true;
}
-
Für die Konsole wohl eher:
#include <string> #define _WIN32_WINNT 0x0500 #define _WIN32_IE 0x0500 #include <windows.h> #include <shellapi.h> bool delete_file( const std::string &filepath ) { std::string filepath_copy = filepath; filepath_copy.append( 1, '\0' ); SHFILEOPSTRUCT file_operation; file_operation.hwnd = GetConsoleWindow( ); file_operation.wFunc = FO_DELETE; file_operation.pFrom = filepath_copy.c_str( ); file_operation.pTo = 0; file_operation.fFlags = FOF_ALLOWUNDO | FOF_WANTNUKEWARNING; return( SHFileOperation( &file_operation ) == 0 ); }
Greetz, Swordfish