Skip to content

Instantly share code, notes, and snippets.

@brennanMKE
Created April 20, 2017 22:23
Show Gist options
  • Save brennanMKE/a0a2ee6aa5a2e2e66297c580c4df0d66 to your computer and use it in GitHub Desktop.
Save brennanMKE/a0a2ee6aa5a2e2e66297c580c4df0d66 to your computer and use it in GitHub Desktop.
Directory Exists at Path in Swift
fileprivate func directoryExistsAtPath(_ path: String) -> Bool {
var isDirectory = ObjCBool(true)
let exists = FileManager.default.fileExists(atPath: path, isDirectory: &isDirectory)
return exists && isDirectory.boolValue
}
@TheImShrey
Copy link

TheImShrey commented Jul 14, 2021

@yarodevuci , I'm assuming this fileExists function does two things, it returns if given path is present and will update boolean using poiter to its address if the provided path is Directory to True else False.

Hence we are doing exists && isDirectory.boolValue in the end.

from documentation:
isDirectory: Upon return, contains true if path is a directory or if the final path element is a symbolic link that points to a directory; otherwise, contains false. If path doesn’t exist, this value is undefined upon return. Pass NULL if you do not need this information.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment