Skip to content

Instantly share code, notes, and snippets.

@mminer
Created September 16, 2016 18:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mminer/3dec6efe9baaf4d465255a6a1b337453 to your computer and use it in GitHub Desktop.
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.
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