如何确定卷是否支持垃圾箱? [英] How to determine if a volume supports Trash?

查看:153
本文介绍了如何确定卷是否支持垃圾箱?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个将删除文件的应用程序.如果该卷支持废纸folder"文件夹,我想将文件移到那里,否则只需将其删除.

I am writing an app that will be deleting files. If the volume supports the Trash folder, I want to move the files there, otherwise just remove them.

这可能只是我的搜索莫霍奇使我失败了,但我找不到解决方法.

It may just be my search mojo failing me, but I cannot find how to do this.

这里的目的是做类似(伪代码)的事情:

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

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

我知道 recycleURLs:completionHandler:,但是,例如对于SMB卷,它会弹出一个对话框,说明如何立即删除文件.我想分别处理文件,以便更新显示.我想我可以使用 recycleURLs:completionHandler:,如果文件系统事件可以在SMB卷上运行,但我不确定它们是否可以运行.

I am aware of recycleURLs:completionHandler: but, for SMB volumes for example, it puts up a dialog about how the file(s) will be immediately deleted. And I would like to deal the the files individually so that I can update a display. I suppose I could use recycleURLs:completionHandler: if File System Events work on SMB volumes but I am not sure they do.

Anyhoo ..是否缺少某些API或我似乎找不到的某些推荐技术?

Anyhoo..Is there some API I am missing or some recommended technique that I just cant seem to find?

推荐答案

Apple Dev论坛中的一个好人找到了答案:

A nice person from the Apple Dev Forums hunted up the answer:

摘自10.8 Foundation发行说明:

NSFileManager废纸s API在Mac OS 10.8中,NSFileManager具有新方法 管理垃圾箱. -[NSFileManager trashItemAtURL:resultingItemURL:error:]将尝试移动该项目 在垃圾箱的给定URL处,返回结果URL 参考.作为此操作的一部分,系统可能会重命名文件 避免名称冲突;如果是这样,则resultItemURL将反映出这一点 新名称.

NSFileManager Trash APIs In Mac OS 10.8, NSFileManager has new methods to manage the Trash. The -[NSFileManager trashItemAtURL:resultingItemURL:error:] will attempt to move the item at the given URL to the trash, returning the resulting URL by reference. As part of this operation, the system may rename the file to avoid name conflicts; if so, the resultingItemURL will reflect this new name.

[snip]

某些卷可能不支持废纸folder"文件夹,因此这些方法将 通过返回NO或nil和NSError来报告失败 NSFeatureUnsupportedError. NSFeatureUnsupportedError是一个新错误 NSCocoaErrorDomain中的代码,指示执行失败 所请求的操作,因为该功能不受支持,或者 因为文件系统缺少该功能,或者所需的库是 丢失或其他类似原因.

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

不确定为什么该文档从未出现在搜索中.

Not sure why that doc never came up on search.

这篇关于如何确定卷是否支持垃圾箱?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆