Mozzak
Mozzak

Reputation: 211

Objective C - How to determine if a folder is a package?

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
}

Upvotes: 0

Views: 380

Answers (1)

CRD
CRD

Reputation: 53010

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.

Upvotes: 1

Related Questions