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.
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.
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.