Knowing if a file is deleted (moved to Trash)

If a file is moved to the Trash then a class implementing FilePresenter will have presentedSubitem(at:didMoveTo:) called. The didMoveTo string seems to follow this pattern:
file:///Users/<USER>/.Trash/<FILENAME>

Of course I can examine the path and look for a component .Trash, but this feels unreliable. Is there a better way?


Of course I can examine the path and look for a component .Trash,
but this feels unreliable.

Indeed. This won’t work reliably in various cases (for example, if the file is on an external volume). Fortunately there is an API that addresses this directly, namely getRelationship(_:of:in:toItemAt:).

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@apple.com"
Knowing if a file is deleted (moved to Trash)
 
 
Q