app.trash - 废纸篓 API
将文件移至废纸篓。
方法
app.trash.moveToTrash(path)
将文件或目录移至废纸篓。
参数:
path(string|array) - 文件路径或路径数组
返回值:
- 单文件:
string, error- 废纸篓中的路径 - 多文件:
array<string>, error- 废纸篓路径数组
-- 移动单个文件
local trashPath, err = app.trash.moveToTrash("/path/to/file.txt")
if trashPath then
app.log.info("已移至: " .. trashPath)
end
-- 移动多个文件
local paths, err = app.trash.moveToTrash({
"/path/to/file1.txt",
"/path/to/file2.txt"
})
示例
安全删除选中文件
function MyPlugin:handleTrash(context)
local count = #context.selectedFiles
if not app.dialog.confirm("确定要将 " .. count .. " 个文件移至废纸篓?") then
return
end
local paths, err = app.trash.moveToTrash(context.selectedFiles)
if paths then
app.notification.show("完成", "已移至废纸篓: " .. #paths .. " 个文件")
else
app.dialog.alert("错误", err or "操作失败")
end
end