当前位置:网站首页>Node queries the path of all files (files or folders) named filename under the target directory
Node queries the path of all files (files or folders) named filename under the target directory
2022-07-25 03:02:00 【cc_ King】
Don't talk much , Direct Gan
const fs = require('fs')
const path = require('path')
/** * Query target All files or folders in the directory are named filename File path * @param {String} dir Look up the catalog * @param {String} filename Name of query file * @returns {Array} All qualified file paths */
function getAllDirbyFilename(dir, filename) {
let dirPath = path.resolve(__dirname, dir);
let files = fs.readdirSync(dirPath); // All file names under this folder ( Folder + file )
let resultArr = [];
files.forEach(file => {
let filePath = dir + '/' + file; // Current file | Path to folder
// Files that meet the query conditions
if (file === filename) {
return resultArr.push(filePath);
}
// Continue searching folders
if (fs.statSync(filePath).isDirectory()) {
resultArr.push(...getAllDirbyFilename(filePath, filename));
}
})
return resultArr;
}
let fileArr = getAllDirbyFilename('./src', 'main.js');
console.log(fileArr);
边栏推荐
- Operator explanation - C language
- Color space (1) - RGB
- Threat report in June: new bank malware malibot poses a threat to mobile banking users
- Strategy mode, just read one article
- JS written test question -- prototype, new, this comprehensive question
- Stm32cubemx quadrature encoder
- JS construct binary tree
- Use unicloud cloud function to decode wechat motion steps in applet
- Use of stm32cubemonitor part I - data plotting and instrument display
- How to take the mold for the picture of 1.54 inch TFT st7789 LCD screen
猜你喜欢

Mid year summary and personal feelings

Wechat sports field reservation of applet completion works applet graduation design (8) graduation design thesis template

Dynamic programming -- Digital DP

Use of stm32cubemonitor part I - data plotting and instrument display

Tp5.1 initialize initialization method (not \u initialize)

Jenkins plug-in development -- plug-in expansion

Preliminary foundation JVM

Flume's study notes

Use pytest + allure to show the chart results (3)

Riotboard development board series notes (6) -- buildreoot building system image
随机推荐
JS written test question -- realize the flat function of array
Ffmpeg 4.3 add custom demuxer
【C】 Advanced knowledge of file operation
Pypi counts the number of Downloads
[stm32f130rct6] idea and code of ultrasonic ranging module
Experiment 4 CTF practice
Use pytest + allure to show the chart results (3)
@Retryable @backoff @recover retry the use of annotations
6.0 cancellation of member registration verification code
New key points of ES6
Keras load history H5 format model error: attributeerror 'STR' object has no attribute 'decode‘
Flume's study notes
Daily three questions 7.15
Resolved (the latest version of selenium reported an error) attributeerror: module 'selenium webdriver‘ has no attribute ‘PhantomJS‘
JS interview question - what is the difference between Es5 and ES6?
It7259q-13, it7259ex-24 feature wearable devices
JS foundation -- regular expression
Tp5.1 initialize initialization method (not \u initialize)
Tp5.1 include include files (reference public files)
Backtracking to solve subset problem