直接上Node脚本
#!/usr/bin/env node
var fs = require("fs")
var path = require("path")
var argv = process.argv;
var root = process.cwd();
var nd_1 = '├── ';
var nd_2 = '│ ';
readDirSync(root)
function readDirSync(path, layers) {
layers = layers || 0;
var pa = fs.readdirSync(path);
pa.forEach(function (ele, index) {
var lstr = '';
for (let i = 0; i < layers; i++) {
lstr += nd_2;
}
var info = fs.statSync(path + "/" + ele);
lstr += nd_1;
lstr += ele;
console.log(lstr);
if (info.isDirectory()) {
readDirSync(path + "/" + ele, (layers + 1));
}
})
}
将其保存为dirtree,并移至/usr/local/bin/下
sudo mv dirtree /usr/local/bin/dirtree
添加执行权限
sudo chmod +x /usr/local/bin/dirtree
赶紧找个目录试一下吧!效果如下
$ dirtree #输入的命令
#下面是执行的效果
├── index.js
├── test
│ ├── index.js
│ ├── lib
│ │ ├── api
│ │ │ ├── network.js
│ │ ├── spiUtil.js
│ │ ├── common
│ │ │ ├── common.js
网友评论