app.trash - Trash API
Move files to the Trash.
Permission: L1 Standard — must be declared in
permissions("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 app.dialog.alert({title = "Confirm", message = "Move " .. count .. " files to the Trash?", buttons = {"Move to Trash", "Cancel"}}) ~= 1 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({title = "Error", message = err or "Operation failed"})
end
end