Represent directory tree with json or object.
for example. windows tree command.
C:.
+---documents
| | a.txt
| | b.txt
| | c.txt
| |
| +---app
| | app_a.txt
| | app_b.txt
| | app_c.txt
| |
| +---music
| \---video
+---downloads
| | a.exe
| | b.exe
| |
| \---test
| test_a.exe
| test_b.exe
|
\---favorites
on the other hand this module.
{
"path": ".\\demo",
"parent_path": ".",
"filename": "demo",
"extension": "",
"is_directory": true,
"children": [
{
"path": ".\\demo\\documents",
"parent_path": ".\\demo",
"filename": "documents",
"extension": "",
"is_directory": true,
"children": [
{
"path": ".\\demo\\documents\\a.txt",
"parent_path": ".\\demo\\documents",
"filename": "a.txt",
"extension": ".txt",
"is_directory": false,
"children": []
},
{
"path": ".\\demo\\documents\\app",
"parent_path": ".\\demo\\documents",
"filename": "app",
"extension": "",
"is_directory": true,
"children": [
{
"path": ".\\demo\\documents\\app\\app_a.txt",
"parent_path": ".\\demo\\documents\\app",
"filename": "app_a.txt",
"extension": ".txt",
"is_directory": false,
"children": []
},
{
"path": ".\\demo\\documents\\app\\app_b.txt",
"parent_path": ".\\demo\\documents\\app",
"filename": "app_b.txt",
"extension": ".txt",
"is_directory": false,
"children": []
},
{
"path": ".\\demo\\documents\\app\\app_c.txt",
"parent_path": ".\\demo\\documents\\app",
"filename": "app_c.txt",
"extension": ".txt",
"is_directory": false,
"children": []
}
]
},
{
"path": ".\\demo\\documents\\b.txt",
"parent_path": ".\\demo\\documents",
"filename": "b.txt",
"extension": ".txt",
"is_directory": false,
"children": []
},
{
"path": ".\\demo\\documents\\c.txt",
"parent_path": ".\\demo\\documents",
"filename": "c.txt",
"extension": ".txt",
"is_directory": false,
"children": []
},
{
"path": ".\\demo\\documents\\music",
"parent_path": ".\\demo\\documents",
"filename": "music",
"extension": "",
"is_directory": true,
"children": []
},
{
"path": ".\\demo\\documents\\video",
"parent_path": ".\\demo\\documents",
"filename": "video",
"extension": "",
"is_directory": true,
"children": []
}
]
},
{
"path": ".\\demo\\downloads",
"parent_path": ".\\demo",
"filename": "downloads",
"extension": "",
"is_directory": true,
"children": [
{
"path": ".\\demo\\downloads\\a.exe",
"parent_path": ".\\demo\\downloads",
"filename": "a.exe",
"extension": ".exe",
"is_directory": false,
"children": []
},
{
"path": ".\\demo\\downloads\\b.exe",
"parent_path": ".\\demo\\downloads",
"filename": "b.exe",
"extension": ".exe",
"is_directory": false,
"children": []
},
{
"path": ".\\demo\\downloads\\test",
"parent_path": ".\\demo\\downloads",
"filename": "test",
"extension": "",
"is_directory": true,
"children": [
{
"path": ".\\demo\\downloads\\test\\test_a.exe",
"parent_path": ".\\demo\\downloads\\test",
"filename": "test_a.exe",
"extension": ".exe",
"is_directory": false,
"children": []
},
{
"path": ".\\demo\\downloads\\test\\test_b.exe",
"parent_path": ".\\demo\\downloads\\test",
"filename": "test_b.exe",
"extension": ".exe",
"is_directory": false,
"children": []
}
]
}
]
},
{
"path": ".\\demo\\favorites",
"parent_path": ".\\demo",
"filename": "favorites",
"extension": "",
"is_directory": true,
"children": []
}
]
}
npm i fs-tree-json
const { tree, treeSync } = require('fs-tree-json');
// async need callback.
tree('.', (result) => {
console.log(result); // return object only.
});
tree('.', './output.json', (result) => {
console.log(result); // and output json.
});
// sync slightly faster than async function.
const syncObject = treeSync('.'); // return object only.
const syncJson = treeSync('.', './output.json'); // and output json.
aurman -S python2
which python2
npm config set python /usr/bin/python2
% gcc --version
gcc (GCC) 9.1.0
% g++ --version
g++ (GCC) 9.1.0
npm i -g windows-build-tools
npm config set msvs_version 2017
npm config set python "C:\Python27\python.exe"
npm i
npm rebuild node-gyp
npm run build
npm run test