Function DeleteToRecycler(
Const FileNames: TDynAnsiStringArray): ByteBool;
Var P: PAnsiChar;
i, i2: Integer;
ShellInfo: TSHFileOpStructA;
Begin
Result := False;
P :=
nil;
Try
i := 0;
For i2 := High(FileNames)
downto 0
do If FileNames[i2] <> '
'
Then Inc(i, Length(FileNames[i2]) + 1);
If i = 0
Then Exit;
P := Memory.Get(i + 2);
(P + i)^ := #0;
(P + i + 1)^ := #0;
For i2 := High(FileNames)
downto 0
do If FileNames[i2] <> '
'
Then Begin
Dec(i, Length(FileNames[i2]) + 1);
Memory.Copy(Pointer(FileNames[i2]), P + i, Length(FileNames[i2]) + 1);
End;
Memory.Zero(@ShellInfo, SizeOf(TSHFileOpStructA));
ShellInfo.Func := foDelete;
ShellInfo.opFrom := P;
ShellInfo.Flags := fofNoConfirmation
or fofAllowUndo
or fofNoErrorUI;
Result := SHFileOperationA(ShellInfo) = S_OK;
Finally
Memory.Free(Pointer(P));
End;
If not Result
Then Begin
Result := True;
For i := High(FileNames)
downto 0
do Begin
Memory.Zero(@ShellInfo, SizeOf(TSHFileOpStructA));
ShellInfo.Func := foDelete;
ShellInfo.opFrom := Pointer(FileNames[i]);
ShellInfo.Flags := fofNoConfirmation
or fofAllowUndo
or fofNoErrorUI;
If SHFileOperationA(ShellInfo) <> S_OK
Then Result := False;
End;
End;
End;
Function DeleteToRecycler(
Const FileNames: TDynWideStringArray): ByteBool;
Var S: WideString;
i: Integer;
ShellInfo: TSHFileOpStructW;
Begin
S := #0;
For i := High(FileNames)
downto 0
do If FileNames[i] <> '
'
Then S := FileNames[i] + #0 + S;
If Length(S) <= 1
Then Begin Result := False; Exit;
End;
Memory.Zero(@ShellInfo, SizeOf(TSHFileOpStructW));
ShellInfo.Func := foDelete;
ShellInfo.opFrom := Pointer(S);
ShellInfo.Flags := fofNoConfirmation
or fofAllowUndo
or fofNoErrorUI;
Result := SHFileOperationW(ShellInfo) = S_OK;
S := '
';
If not Result
Then Begin
Result := True;
For i := High(FileNames)
downto 0
do Begin
Memory.Zero(@ShellInfo, SizeOf(TSHFileOpStructW));
ShellInfo.Func := foDelete;
ShellInfo.opFrom := Pointer(FileNames[i]);
ShellInfo.Flags := fofNoConfirmation
or fofAllowUndo
or fofNoErrorUI;
If SHFileOperationW(ShellInfo) <> S_OK
Then Result := False;
End;
End;
End;