Objective C - How to determine if a folder is a pa

2019-08-19 02:33发布

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

My question is:

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.

Any advise would be appreciated.

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?

I solved it as:

NSNumber *isPackage;
NSError *error = nil;

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

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

1条回答
Ridiculous、
2楼-- · 2019-08-19 03:39

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.

查看更多
登录 后发表回答