How to determine if a volume supports trash?

I am writing an application that will delete files. If the volume supports the Trash folder, I want to move the files there, otherwise just delete them.

It may only be my search for mojo, putting up with me, but I cannot find how to do it.

The goal here is to do something like (pseudocode):

if (itemURL on volume that supports Trash) use trashItemAtURL:resultingItemURL:error: else use removeItemAtURL:error: 

I am aware of recycleURLs: completHandler: but, for example, for SMB volumes, it places a dialog about how files (files) will be deleted immediately. And I would like to process the files individually to update the display. I suggest that I could use recycleURLs: completeHandler: if file system events work on SMB volumes, but I'm not sure if they do.

Anyhoo .. Is there some kind of API I'm missing out on, or some recommended method that I just can't find?

+4
source share
1 answer

The good man from the Apple Dev forums hunted the answer:

From the 10.8 Foundation Release Notes:

NSFileManager Trash API On Mac OS 10.8, NSFileManager has new methods for managing trash. - [NSFileManager trashItemAtURL: resultItemURL: error:] will try to move the item to the specified basket URL, returning the received Help URL. As part of this operation, the system can rename the file to avoid name conflicts; if so, the final result will reflect this new name.

[incision]

Some volumes may not support the Trash folder, so these methods will crash the report by returning NO or nil and NSError with NSFeatureUnsupportedError. NSFeatureUnsupportedError is a new code error in NSCocoaErrorDomain that indicates an inability to perform the requested operation because the function is not supported, either because the function is missing on the file system, or the required libraries are missing or other similar reasons.

I do not know why this document never came in search of.

+3
source

Source: https://habr.com/ru/post/1499296/


All Articles