Search code examples
objective-ccocoansurlvolumerecycle-bin

How to know whether a file can be moved to the trash in Cocoa


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].


Solution

  • 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.