Currently I'm able to trash selected user files. The question is how to know whether the volume of that file supports trashing. For example, external USB sticks just have a local trash folder, while trashing a file on a remote Mac is not allowed (even from the Finder), it can only be deleted. I didn't find any appropriate constant among the NSURLVolume[...]
ones to use with [NSURL getResourceValue:forKey:error]
.
How to know whether a file can be moved to the trash in Cocoa
Asked Answered
I ended up checking the result of the following method:
FileManager.default.url(for: .trashDirectory, in: .userDomainMask, appropriateFor: url, create: false)
where url
is the url of the volume or a file on that volume.
© 2022 - 2024 — McMap. All rights reserved.
NSFileManager
andtrashItemAtURL:resultingItemURL:error:
see #18480022 – Saari