Created
September 16, 2016 18:10
-
-
Save mminer/3dec6efe9baaf4d465255a6a1b337453 to your computer and use it in GitHub Desktop.
Function that walks up directory tree to find given path's parent directory.
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
func parent(ofPath path: String, levels: Int) -> String { | |
var parentPath = path | |
for _ in 1...levels { | |
parentPath = (parentPath as NSString).deletingLastPathComponent | |
} | |
return parentPath | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment