Code Monkey home page Code Monkey logo

dirtree's Introduction

dirTree

以树状图列出目录内容的nodejs实现,类似于linux下的tree命令

结构

dirTree  ------根目录
  │
  ├─lib  ------相关函数目录
  │  │
  │  └─dirTree.js  ------相关函数接口
  │
  ├─README.md  ------说明文档
  │
  ├─conf.js  ------配置文件
  │
  └─tree.js  ------入口文件

例子

配置conf.js

module.exports = {
    "name": "dirTree",       // 根目录名 
    "path": "./",            // 根目录路径
    "ignoreList": [/^\./],   // 忽略列表,当正则匹配成功时忽略该文件/目录
    "type": "console"        // 打印方式,console表示打印到控制台
}

运行tree.js

node tree.js

程序将会dfs遍历目录得到一个树状的json对象:

{
  name: 'dirTree',
  type: 'dir',
  childD: [{
    name: 'lib',
    type: 'dir',
    childD: [],
    childF: [{name: 'dirTree.js', type: 'file'}]
  }],
  childF: [{name: 'conf.js', type: 'file'},
    {name: 'tree.js', type: 'file'}]
}

打印树状图到控制台:

dirTree
  │
  ├─lib
  │  │
  │  └dirTree.js
  │
  ├─README.md
  │
  ├─conf.js
  │
  └─tree.js

dirtree's People

Contributors

blackhole1 avatar guzheyuan avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.