将目录移至垃圾桶 [英] Move directory to trash

查看:101
本文介绍了将目录移至垃圾桶的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要将所有内容的目录移至垃圾桶。
我在文档中找到 NSWorkspaceRecycleOperation 操作,并编写了以下代码:

I need to move directory with all content to trash. I find in documentation NSWorkspaceRecycleOperation operation, and wrote this code:

NSString *path = [NSString stringWithString:@"/Users/test/Desktop/test"];

NSArray *dirContents = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:path error:nil];

[[NSWorkspace sharedWorkspace] performFileOperation:NSWorkspaceRecycleOperation 
                                             source:path 
                                        destination:@"" 
                                              files:dirContents 
                                                tag:nil];

它移动到所有内容,但不移动目录。那么,我该怎么做呢?

It move to trash all contents, but don't move directory itself. So, how can i do this?

推荐答案

目前你只对目录内容执行回收操作。给一个目录 dir 到垃圾桶,使用类似下面的代替:

You are currently only performing the recycle operation on the directories contents. Given a directory dir to trash, use something like the following instead:

[[NSWorkspace sharedWorkspace] performFileOperation:NSWorkspaceRecycleOperation 
                               source:[dir stringByDeletingLastPathComponent]
                               destination:@"" 
                               files:[NSArray arrayWithObject:[dir lastPathComponent]]
                               tag:nil];

这篇关于将目录移至垃圾桶的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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