We delete the file to the recycle bin without confirmation or any dialog boxes.
1 2 3 4 5 6 7 8 9 10 |
Uses Winapi.ShellAPI; ... var filePath: WideString; begin filePath:= 'C:\My_file.txt'; delFileToRecycle(filePath); end; |
Options
filePath - path to the file
Result
True - if the file was deleted, False - if not, or the file does not exist.
1 2 3 4 5 6 7 8 9 10 11 |
function delFileToRecycle(filePath: string): Boolean; var FileOp: TSHFileOpStruct; begin FillChar(FileOp, SizeOf(FileOp), 0); FileOp.wFunc := FO_DELETE; FileOp.pFrom := PChar(filePath + #0#0); FileOp.fFlags := FOF_ALLOWUNDO or FOF_NOERRORUI or FOF_SILENT or FOF_NOCONFIRMATION or FOF_NOCONFIRMMKDIR ; Result := (SHFileOperation(FileOp) = 0) and (not FileOp.fAnyOperationsAborted); end; |