I have the following code:
fs.readdir('.', (err, files) => {
files.forEach(file => {
if (file.match(/^\Qcustom_\E.+\d\Q.pid\E/)) {
var pid = fs.readfile(file, function (err, data) {
if (err) throw err;
return data.toString();
});
console.log(pid);
}
});
});
And in my directory, I have several files such as custom_Component1.pid
, custom_Component2.pid
, custom_NewComponent3.pid
, etc. with each of these containing just a single line (the pid).
However, the code above doesn't match the files, even though according to my Regex101, the regex is correct.
If I console.log(file)
, the filename shows up exactly how I expect it to, just as custom_Component1.pid