Reputation: 7204
How can I tell if a file is a package rather than a directory?
var isDir = ObjCBool(false)
let exists = NSFileManager.defaultManager().fileExistsAtPath(path, isDirectory: &isDir)
return isDir.boolValue
This code returns true for both directories and packages.
Upvotes: 1
Views: 276
Reputation: 4381
There’s a Cocoa method, isFilePackageAtPath
, on NSWorkspace for that.
import Cocoa
let sw = NSWorkspace.sharedWorkspace()
if sw.isFilePackageAtPath("/Applications/Xcode.app") {
// True, so this will execute.
}
if sw.isFilePackageAtPath("/usr/bin") {
// False, so this won't execute.
}
Upvotes: 4