Skip to content

Instantly share code, notes, and snippets.

@townivan
Created January 8, 2019 19:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save townivan/00d12270c14d269512d33845e0bc274b to your computer and use it in GitHub Desktop.
Save townivan/00d12270c14d269512d33845e0bc274b to your computer and use it in GitHub Desktop.
Read all of the .html files in a folder without using a library like glob
const fs = require('fs');
const targetPath = './src/pages/'
// *.html files
let fileNamesArray = fs.readdirSync(targetPath).filter( (file) => {
return file.includes('.html')
})
// 'all-comps.html', 'c090.html', 'c100.html', 'c101.html', 'c102.html', 'index.html' ]
// c*.html files
let fileNamesArray = fs.readdirSync(targetPath).filter( (file) => {
return file.includes('.html') && file.substring(0,1) == 'c' // c*.html files
})
// [ 'c090.html', 'c100.html', 'c101.html', 'c102.html' ]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment