Created
August 9, 2014 15:19
-
-
Save tsuyukimakoto/91de875fca0d3b01d2c1 to your computer and use it in GitHub Desktop.
tree (print file list recursively)
This file contains hidden or 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
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