Skip to content

Instantly share code, notes, and snippets.

@fawazahmed0
Created November 22, 2025 12:04
Show Gist options
  • Select an option

  • Save fawazahmed0/1c7ef04291f152e13515a78433dee785 to your computer and use it in GitHub Desktop.

Select an option

Save fawazahmed0/1c7ef04291f152e13515a78433dee785 to your computer and use it in GitHub Desktop.
Search files with JS
const fs = require('fs/promises')
const path = require('path')
const pathToDir = path.join(__dirname, '.')
const textToSearch = /\.docx/i
async function main(){
let result = await fs.readdir(pathToDir, { withFileTypes: true, recursive: true })
result = result.filter(e => textToSearch.test(e.name))
console.log(result.map(e => path.join(e.parentPath, e.name)))
}
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment