RecycledItem

Throw a file away and still get it back: a recycled file or folder you can restore, or delete for good.

PathHandler:RecycleAsync() moves the file or folder into a .ShotRecycleBin folder on its own drive and gives a RecycledItem. RestoreAsync moves it back to OriginalPath unless something is there now, and DeleteAsync removes it for good. Today a RecycledItem sits outside the tree: its Parent is nil.

ShotInstancenot creatableFiles

PathHandler:RecycleAsync() gives one.

Example

Recycle and restoreShotScript
-- Recycles todo.txt, brings it back, then recycles it again and deletes it for good.
use FileService
use TimeService
local todo = FileService:GetPathHandler("todo.txt")
todo:OverwriteAsync("buy milk")
local item, why = todo:RecycleAsync()
if not item then
	error("couldn't recycle todo.txt: " .. tostring(why))
end
print("recycled, OriginalPath " .. item.OriginalPath .. ", todo.txt still there: " .. tostring(todo:ExistsAsync()))
print("RecycledAt is now: " .. tostring(math.abs(TimeService:Now() - item.RecycledAt) < 5))

local back = item:RestoreAsync()
local text = if back then back:ReadStringAsync() else nil
print("restored: " .. tostring(text))

local again = todo:RecycleAsync()
local inBin = if again then again.Path else nil
if again and inBin then
	print("in the bin as " .. inBin.BaseName .. ": " .. tostring(inBin:ExistsAsync()))
	again:DeleteAsync()
	print("after DeleteAsync, in the bin: " .. tostring(inBin:ExistsAsync()) .. ", todo.txt: " .. tostring(todo:ExistsAsync()))
end
What it printedOutput
recycled, OriginalPath todo.txt, todo.txt still there: false
RecycledAt is now: true
restored: buy milk
in the bin as todo.txt: true
after DeleteAsync, in the bin: false, todo.txt: false

Properties

NameTypeDefaultDescription
OriginalPathstringread-onlyWhere the file or folder was before RecycleAsync moved it, and where RestoreAsync puts it back.
PathPathHandler?read-onlyA PathHandler for where it sits now, inside the recycle bin.
RecycledAtnumber0
read-only
When it was recycled, in seconds since 1970.

Methods

NameArgumentsReturnsDescription
DeleteAsync
yields
()(boolean, string?)Waits to delete it from the recycle bin for good; it can't be restored after that.
RestoreAsync
yields
()(PathHandler?, string?)Waits to move it back to OriginalPath; nil and why when something is there now.
From ShotInstance 33