This file ( 2kB ) exceeds the allowed full mode (48 kb) size.
The editor full hight is disabled, only scrolling is allowed..
If you wish to edit a file, it is recommended to use the scroll mode as some users do not like the full height
mode, although some users like it.
const fs = require('fs');
const path = require('path');
function readdirRecursive(startDir) {
let readDirQueue = [],
fileList = [];
function readDir(dir) {
function getItemList(readDir) {
return new Promise((resolve, reject) => {
fs.readdir(readDir, (err, itemList) => {
if (err) {
return reject();
}
// resolve with parent path added to each item
resolve(itemList.map((item) => path.resolve(readDir, item)));
});
});
}
function getItemListStat(itemList) {
function getStat(itemPath) {
return new Promise((resolve, reject) => {
fs.stat(itemPath, (err, stat) => {
if (err) {
return reject();
}
// resolve with item path and if directory
resolve({itemPath, isDirectory: stat.isDirectory()});
});
});
}
// stat all items in list
return Promise.all(itemList.map(getStat));
}
function processItemList(itemList) {
for (let {itemPath, isDirectory} of itemList) {
// if directory add to queue
if (isDirectory) {
readDirQueue.push(itemPath);
continue;
}
// add file to list
fileList.push(itemPath);
}
// if queue, process next item recursive
if (readDirQueue.length > 0) {
return readDir(readDirQueue.shift());
}
// finished - return file list
return fileList;
}
// read item list from directory, stat each item then walk result
return getItemList(dir)
.then(getItemListStat)
.then(processItemList);
}
// commence reading at the top
return readDir(startDir);
}
module.exports = readdirRecursive