Created
November 22, 2025 12:04
-
-
Save fawazahmed0/1c7ef04291f152e13515a78433dee785 to your computer and use it in GitHub Desktop.
Search files with JS
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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