The following works well for me when trashing a file which is on my primary disk. It also works when the file is on an SMB network volume, where the Finder's trashing confirmation message says "This item will be deleted immediately." I'm reasonably sure it's not inside any hidden folder in the latter case, and so I wouldn't say it's "In the trash", but whatever :)
extension FileManager {
public func isInTrash(_ file: URL) -> Bool {
var relationship: URLRelationship = .other
try? getRelationship(
&relationship,
of: .trashDirectory,
in: .allDomainsMask,
toItemAt: file
)
return relationship == .contains
}
}
Unfortunately when I trash a file which is on an external disk (in my test case an SD Card), the above returns false. Any thoughts on how to detect this edge case?