0

I have these files in folder X: 1.js 2.js, 3.js and this is my code

const commandFiles = fs.readdirSync('./X');

for (const file of commandFiles) {
    const files= require(`./X/${file}`);
}

This currently gets the files 1,2,3 and stores it under files

I want to add a subfolder within folder X with more .js files here's an example:

  • X=>contains 1.js, 2.js,3.js and folder Y in it
  • Y=>contains a.js,b.js

So how would I add these new js files in folder Y to the const files?

Anonymous
  • 49
  • 1
  • 1
  • 9
  • This looks to answer your question: https://stackoverflow.com/a/40896897/127606 – Jarede Jan 12 '18 at 16:06
  • @Jarede That answer is to get the directories, I want to get the js files – Anonymous Jan 12 '18 at 16:48
  • 1
    You can extrapolate from that answer and your current code to get what you want. – Jarede Jan 12 '18 at 16:55
  • @Jarede I don't know how to... – Anonymous Jan 12 '18 at 17:02
  • 1
    We're not going to write the code for you. that isn't the point of SO. you've got this far, you've been given the next piece of the puzzle, you can try to put them together, then come back and create a new question for where it's going wrong. – Jarede Jan 12 '18 at 17:28
  • @Jarede Like I said i don't know how! i'm just going to but a.js,b.js in folder X :/ – Anonymous Jan 12 '18 at 19:36

0 Answers0