This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict' | |
const fs = require('fs') | |
const path = require('path') | |
const rootFolder = __dirname // Your folder | |
const spider = (folder = rootFolder, state = []) => { | |
fs.readdirSync(folder).forEach(file => { | |
let dir = path.join(folder, file), | |
isDir = fs.lstatSync(dir).isDirectory() | |
let children = isDir ? spider(dir) : null | |
state.push({ | |
file: file, | |
isDir: isDir, | |
chidlren: children | |
}) | |
}) | |
state.sort(a => a.isDir ? -1 : 1) | |
return state | |
} | |
/* | |
Индексируем все папки | |
*/ | |
const tree = spider() | |
console.log(tree) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment