Skip to content

Instantly share code, notes, and snippets.

@tsuyukimakoto
Created August 9, 2014 15:19
Show Gist options
  • Save tsuyukimakoto/91de875fca0d3b01d2c1 to your computer and use it in GitHub Desktop.
Save tsuyukimakoto/91de875fca0d3b01d2c1 to your computer and use it in GitHub Desktop.
tree (print file list recursively)
import Foundation
import Cocoa
var fm = NSFileManager()
var err:NSError?
var err2:NSError?
var indent_cnt = 0
func indent(depth:Int) -> String {
var result = ""
for i in 1...depth {
result += " "
}
return result
}
func tree(basePath:String) {
let indent_str = indent(indent_cnt)
var lst = fm.contentsOfDirectoryAtPath(basePath, error: &err)
for v in lst {
let pth = basePath + "/" + (v as String)
let d = fm.attributesOfItemAtPath(pth, error: &err2)
if (d["NSFileType"] as NSString == "NSFileTypeDirectory") {
indent_cnt += 1
tree(pth)
indent_cnt -= 1
}
println(indent_str + pth)
println(d["NSFileType"])
}
}
// let _basePath = "~".stringByExpandingTildeInPath
// tree(_basePath)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment