app.trash - Trash API
Move files to the Trash.
Methods
app.trash.moveToTrash(path)
Move a file or directory to the Trash.
Parameters:
path(string|array) - file path or array of paths
Returns:
- Single file:
string, error- path in the Trash - Multiple files:
array<string>, error- array of Trash paths
-- Move a single file
local trashPath, err = app.trash.moveToTrash("/path/to/file.txt")
if trashPath then
app.log.info("Moved to: " .. trashPath)
end
-- Move multiple files
local paths, err = app.trash.moveToTrash({
"/path/to/file1.txt",
"/path/to/file2.txt"
})
Examples
Safely Delete Selected Files
function MyPlugin:handleTrash(context)
local count = #context.selectedFiles
if not app.dialog.confirm("Are you sure you want to move " .. count .. " files to the Trash?") then
return
end
local paths, err = app.trash.moveToTrash(context.selectedFiles)
if paths then
app.notification.show("Done", "Moved " .. #paths .. " files to the Trash")
else
app.dialog.alert("Error", err or "Operation failed")
end
end