Skip to content

Instantly share code, notes, and snippets.

@victorchee
Created July 21, 2015 11:26
Show Gist options
  • Save victorchee/5be478c25d1d0f659d13 to your computer and use it in GitHub Desktop.
Save victorchee/5be478c25d1d0f659d13 to your computer and use it in GitHub Desktop.
Print Directory Content
func printDirectoryContent(path: String) {
let contents = NSFileManager.defaultManager().contentsOfDirectoryAtPath(path, error: nil)
if let files = contents {
for file in files as! [String] {
let filePath = path.stringByAppendingPathComponent(file)
let attributes = NSFileManager.defaultManager().attributesOfItemAtPath(filePath, error: nil)!
if attributes[NSFileType] as! String == NSFileTypeDirectory {
printDirectoryContent(filePath)
} else {
if NSFileManager.defaultManager().isUbiquitousItemAtURL(NSURL(fileURLWithPath: filePath)!) {
println(filePath)
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment