Skip to content

Instantly share code, notes, and snippets.

@azu
Created May 14, 2010 14:03
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save azu/401178 to your computer and use it in GitHub Desktop.
NILScript用のスクリプト
/*
tree コマンド
tree.ng [ディレクトリパス コピーするディレクトリの深さ]
第一引数 dirPath
第二引数 depth
1ならそのディレクトリ直下のみ
2なら一つ下のフォルダまで
3...
*/
var dir=new Directory(Main.arguments[2]||cwd());// なければカレントディレクトリ
var limitDepth = (Main.arguments[3]|| 2);
if(dir.exists){
var result = [],cnt={};
result.push(dir.name);
getDirTree(dir)
}else{
println(dir.path+" is not exist");
}
// クリップボードへ入れる
require("Clipboard").Clipboard.text = result.join("\n");
function getDirTree(dir,index){
if(!index){
var index = 0;
}
if(index >= limitDepth){
index = 0;
return;
}
var i = 0;
var branchSign = (index==0)? "├" : "│"+Array(3*index).join(" ")+"├";
var limbSign = (index==0)? "└" : "│"+Array(3*index).join(" ")+"└";
var brachDir = (index==0)? "" : "│"+Array(3*index).join(" ")+"├";
// dir.find("*") dir.children
cnt[dir.path] = dir.children.count();
for(var d in dir.children){
i++;
if(d.size){
if(cnt[dir.path] == i){
result.push(limbSign+d.name);
}else{
result.push(branchSign+d.name);
}
}else{
if(cnt[dir.path] == i){
result.push(limbSign+d.name+"[DIR]");
}else{
result.push(branchSign+d.name+"[DIR]");
}
getDirTree(d , 1+index)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment