I have the following routine, which I found on the internet, to delete to the recycle bin some folders that contain files and other folders. It works fine unless there is a zip file. Then it gives me the error 120 (= this function is not supported), even if I change the extension from zip to eg bck. I guess the function sees the zip file as a folder but it can't handle it and throws an error.
Does anyone know how I can overcome this problem?
function recycleFile(fileName: string): boolean;
var
fos: TSHFileOpStruct;
erNo : integer;
begin
setlength(fileName, length(fileName) + 1);
fileName[length(fileName)] := #0;
FillChar(fos, SizeOf(fos), 0);
with fos do
begin
wFunc := FO_DELETE;
pFrom := PChar(fileName);
fFlags := FOF_ALLOWUNDO or FOF_NOCONFIRMATION or FOF_NOERRORUI;
end;
erNo := ShFileOperation(fos);
if erNo <> 0 then showmessage(intToStr(erNo));
result := erNo = 0;
end;
This code works for me (using Delphi 12, on Windows 11):
It can include folders that contain .zip files.