Search code examples
node.jsglob

Selecting all files of certain extensions in specified directory and below with Glob & Node.js


Why below glob does not select the files directly below Pages/Open?

/Pages/Open/**/*.pug

enter image description here

🌎 Fiddle


Solution

  • const glob = require('glob')
    
    glob("./Pages/Open/**/*.pug", (er, files) => {
      console.log({
        files: files
      })
      // outputs the following ...
      // {
      //   files: [
      //     './Pages/Open/_Partial.pug',
      //     './Pages/Open/EntryPoint.pug',
      //     './Pages/Open/Top/_Partial.pug',
      //     './Pages/Open/Top/_SubDirectory2/_Partial.pug',
      //     './Pages/Open/Top/_SubDirectory2/NotPartial.pug',
      //     './Pages/Open/Top/EntryPoint.pug',
      //     './Pages/Open/Top/SubDirectory1/_Partial.pug',
      //     './Pages/Open/Top/SubDirectory1/NotPartial.pug'
      //   ]
      // }
    })