Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

how to get folder names with fs

const fs = require('fs');
const path = require('path');

function flatten(lists) {
  return lists.reduce((a, b) => a.concat(b), []);
}

function getDirectories(srcpath) {
  return fs.readdirSync(srcpath)
    .map(file => path.join(srcpath, file))
    .filter(path => fs.statSync(path).isDirectory());
}

function getDirectoriesRecursive(srcpath) {
  return [srcpath, ...flatten(getDirectories(srcpath).map(getDirectoriesRecursive))];
}
Comment

PREVIOUS NEXT
Code Example
Javascript :: javascript string remove substring 
Javascript :: javascript generate random number 
Javascript :: stop page refresh on button click react 
Javascript :: js how to find element using id 
Javascript :: for loop set timeout 
Javascript :: make copy of date javascript 
Javascript :: move canvas element to mouse 
Javascript :: click counter in js 
Javascript :: fetch Response object get content type 
Javascript :: upload preview image js 
Javascript :: nepali date picker 
Javascript :: js compare values of two arrays 
Javascript :: how to enable click copy function using js 
Javascript :: date regex format 
Javascript :: add on click to div using jquery 
Javascript :: js undici fetch data 
Javascript :: optional chaining javascript 
Javascript :: string indexing in js 
Javascript :: save image jpg javascript 
Javascript :: how to play background sound js 
Javascript :: vue router refresh page not found 
Javascript :: ajax select2 
Javascript :: Create MD5 hash with Node.js 
Javascript :: promise all then 
Javascript :: body-parser deprecated 
Javascript :: javascript convert string with square brackets to array 
Javascript :: what is virtual dom in react 
Javascript :: ngrok live port vue js 
Javascript :: moment.add 
Javascript :: nodejs fs create file if not exists 
ADD CONTENT
Topic
Content
Source link
Name
1+4 =