How do I search for a specific file by name and extension in a working directory, regardless of the file's path from inside that working directory?
For example, if we are searching for foo.txt
inside our first working directory, but it's located within a file path like the example below
workDir/folder2/is/foo/directory/foo.txt
Then say for further example, we want to then search for foo.txt
inside our second working directory, but the file is located within a different file path like below
workDir/folder11/this/way/to/foo.txt
How would I find foo.txt
regardless of the file's path, inside a working directory?
I am Using the below JavaScript code in my NodeJS project's controller.js file to try and achieve this.
NOTE: In real-time, every working directory this would be used on, would be named differently
controller.js
var fooPath = GetFooPath(data, path.join(workDir, "folder11/"));
if (fooPath == -1) {
console.log("Cannot find the foo file!");
return;
}
fs.readdirSync
.folder2
folder3
etc, then search for the file inside of those directories? Sorry I am still new to JavaScript and NodeJS