I use this code to delete whole directories:
uses
ShellApi;
function DelDir(dir: string): Boolean;
var
fos: TSHFileOpStruct;
begin
ZeroMemory(@fos, SizeOf(fos));
with fos do
begin
wFunc := FO_DELETE;
fFlags := FOF_SILENT or FOF_NOCONFIRMATION;
pFrom := PChar(dir + #0);
end;
Result := (0 = ShFileOperation(fos));
end;
Are there any flags I can set to allow for permanent removal of deleted directories?
By permanent removal, I mean it won't show up in the recycle bin after it is deleted because this is what happens when I use the DelDir Function.
Try to set
FileOpStruct.pTo := nil;
Example:
function DeleteTree(const APath: String): Boolean;
var
FileOpStruct : TShFileOpStruct;
ErrorCode: Integer;
begin
Result := False;
if DirectoryExists(APath) then begin
FillChar(FileOpStruct, SizeOf(FileOpStruct), #0);
FileOpStruct.Wnd := 0;
FileOpStruct.wFunc := FO_DELETE;
FileOpStruct.pFrom := PChar(APath + #0#0);
FileOpStruct.pTo := nil;
FileOpStruct.fFlags := FOF_SILENT or FOF_NOCONFIRMATION or FOF_NOERRORUI or FOF_NOCONFIRMMKDIR;
FileOpStruct.lpszProgressTitle := nil;
ErrorCode := ShFileOperation(FileOpStruct);
Result := ErrorCode = 0;
end;
end;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With