Created
April 20, 2017 22:23
-
-
Save brennanMKE/a0a2ee6aa5a2e2e66297c580c4df0d66 to your computer and use it in GitHub Desktop.
Directory Exists at Path in Swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fileprivate func directoryExistsAtPath(_ path: String) -> Bool { | |
var isDirectory = ObjCBool(true) | |
let exists = FileManager.default.fileExists(atPath: path, isDirectory: &isDirectory) | |
return exists && isDirectory.boolValue | |
} |
@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
@venkat20390,
fileExists
must conform to the way OS file system treats folders.If
test
andTest
are different folders on file system - thenFileManager
should treat them as different folders