Skip to content

Instantly share code, notes, and snippets.

@faforty faforty/spider files
Created Jun 19, 2017

Embed
What would you like to do?
'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
You can’t perform that action at this time.