Skip to content

Instantly share code, notes, and snippets.

@hawkeye64
Created November 18, 2018 19:20
Show Gist options
  • Save hawkeye64/f29d008f22ceae0733dcb4fdb1af5baa to your computer and use it in GitHub Desktop.
Save hawkeye64/f29d008f22ceae0733dcb4fdb1af5baa to your computer and use it in GitHub Desktop.
getFolders and getFolderContents
getFolders: function (absolutePath) {
let folders = []
// check incoming arg
if (!absolutePath || typeof absolutePath !== 'string') {
return folders
}
for (const fileInfo of walkFolders(absolutePath, false)) {
// all files and folders
if ('error' in fileInfo) {
console.error(`Error: ${fileInfo.rootDir} - ${fileInfo.error}`)
continue
}
// we only want folders
if (!fileInfo.isDir) {
continue
}
const node = this.createNode(fileInfo)
folders.push(node)
}
return folders
},
getFolderContents: function (folder) {
let contents = []
// check incoming arg
if (!folder || typeof folder !== 'string') {
return contents
}
for (const fileInfo of walkFolders(folder, false)) {
// all files and folders
if ('error' in fileInfo) {
console.error(`Error: ${fileInfo.rootDir} - ${fileInfo.error}`)
continue
}
const node = this.createNode(fileInfo)
contents.push(node)
}
return contents
},
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment