title: NodeJS / discord.js: Read all files in the folders of a specific directory
body: <p>I have a Discord bot that I'm coding, and one thing I'm doing with it is separating all commands into subfolders based on the category they're in <em>(Utility, System, etc)</em>.</p>
  
  <p>The issue I'm having is that I'm unsure of how to find all the folders in the <code>/commands</code> directory, then read all the files from all these folders. I've already specified to read all the folders inside the directory, now I need all the subfolders (and files in them) to be read.</p>
  
  <p>Can I get some help on this? Thanks in advance!</p>
  
  <hr>
  
  <p>[EDIT: addresses comment from initial post] Here's the current code I have, which currently just loads all the files it finds in the base directories (and not subfolders):</p>
  
  <pre class="lang-js prettyprint-override"><code>const init = async () =&gt; {
    const cmdFiles = await readdir("commands");
    client.logger.log(`Loading a total of ${cmdFiles.length} commands.`);
    cmdFiles.forEach(f =&gt; {
      if (!f.endsWith(".js")) return;
      const response = client.loadCommand(f);
      if (response) console.log(response);
    });
  
    const evtFiles = await readdir("./events/");
    client.logger.log(`Loading a total of ${evtFiles.length} events.`);
    evtFiles.forEach(file =&gt; {
      const eventName = file.split(".")[0];
      client.logger.log(`Loading Event: ${eventName}`);
      const event = require(`./events/${file}`);
      client.on(eventName, event.bind(null, client));
    });
  
    client.levelCache = {};
    for (let i = 0; i &lt; client.config.permLevels.length; i++) {
      const thisLevel = client.config.permLevels[i];
      client.levelCache[thisLevel.name] = thisLevel.level;
    }
  
    client.login(client.config.token);
  };
  </code></pre>