目标C-如何确定文件夹是否为包? [英] Objective C - How to determine if a folder is a package?

查看:94
本文介绍了目标C-如何确定文件夹是否为包?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

App软件包基本上是文件夹,您可以像读取任何文件夹一样读取其内容.我明白了.

App Packages are basically folders and you can read their contents just like any folders. I understood this.

我的问题是:

如果我有一个名为folderA的文件夹,该文件夹包含文件,一个名为PackageA的软件包,其中包含文件,我如何以编程方式分辨出什么是普通文件夹,什么是软件包?

If I have a folder called folderA which has files and a package called PackageA which has files, how can I programmatically tell what is a normal folder and what is a package ?

在我的应用程序中,我需要排除任何软件包,但要处理任何普通文件夹.

In my application I need to exclude any packages but process any normal folders.

任何建议将不胜感激.

我试图通过NSBundle进行检查,但是普通文件夹和软件包文件夹都是NSBundle.我希望不是.我确定有一个财产可以告诉我吗?

I have tried to check via NSBundle but both normal folder as well as package folder is an NSBundle. I was hoping one is not. I am sure there is a property that will tell me that?

我将其解决为:

NSNumber *isPackage;
NSError *error = nil;

[filePath getResourceValue:&isPackage forKey:NSURLIsPackageKey error:&error];

if( [isPackage integerValue] == 1)
{
    // treat as package
}

推荐答案

执行此操作的方法有多种,现代"方法是使用NSURLgetResourceValue:forKey:error:方法(或其同级方法之一).确定NSURL实例是否引用程序包的关键是NSURLIsPackageKey.

There are multiple ways to do this, the "modern" way is to use NSURL's getResourceValue:forKey:error: method (or one of its siblings). The key for determining whether the NSURL instance references a package is NSURLIsPackageKey.

这篇关于目标C-如何确定文件夹是否为包?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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