get directory tree
Get a tree view of the directory structure.
yarn add global @fremango/dir-tree
#or
npm i -g @fremango/dir-tree
dir-tree <dir> [options]
const { dirTree, scanDir } = require("dir-tree");
const dir = scanDir({
dir: "./"
});
console.log("dir for Object", JSON.stringfly(dir, null, 2));
const tree = dirTree({
dir: "./"
});
console.log("Tree: ", tree);
Scan the directory with the configured options, return directory struct object
scanDir(Options, callback)
return dirStruct
name | type | default | desc |
---|---|---|---|
name | string | ‘’ | directory name |
isDir | boolean | false | is directory |
path | string | ‘’ | directory absolute path |
children | dirStruct[] | [] | if isDir is true , children is this directory’s children directory |
custom the structure of each item
(itemStruct) => itemStruct
name | type | desc |
---|---|---|
itemStruct | dirStruct | directory’s struct object |
return a tree view of the directory structure.
dirTree(options)
desc: Scan the depth of the directory, if it is 0, scan all directories and their subdirectories
type: number
default: 0
use in cli: -d <number>
or --deep <number>
desc: Ignored directory
type: string[]
default: undefined
use in cli: -i "<dir>,<dir>,..."
or --ignore "<dir>,<dir>,..."
desc: Don’t scan subdirectories of this directory
type: string[]
default: undefined
use in cli: -n "<dir>,<dir>,..."
or --noChild "<dir>,<dir>,..."
desc: Output color text
type: Boolean
default: true
use in cli: --no-color
disabled color text