I am running this simple code. from here How to read all file with specified ext in a dir?.
this is the ttst.js
const fs = require('fs'); const path = require('path'); fs.readdir("PLR", (err, files) => { if (err) return; files.forEach(f => { var data = [] const ext = path.extname(f) if (ext == ".rtf") { fs.readFile(f, 'utf8', function read(err, content) { if (err) { throw err; } data.push(content); Console.log(data); }); } }); }); I am getting error path not found.
C:\Users\rahulkumar.patel\Desktop\ttst.js:12 throw err; ^ Error: ENOENT: no such file or directory, open 'C:\Users\username\Deskto p\11.txt' at Error (native) 11.txt is file in plr folder.
So it is identifying each files in plr but while doing something its ommiting the dir plr itself. Path really problematic in node windows.
I also tried similar solution but the same problem. fs.readfile omiting dir. How to give exact directory.
var fs = require('fs'); fs.readdir("\htmls", function(err, files) { files .filter(function(file) { return file.substr(-5) === '.html'; }) .forEach(function(file) { fs.readFile(file, 'utf-8', function(err, contents) { if (err) throw err; inspectFile(contents); }); }); }); function inspectFile(contents) { console.log(contents); } Error: ENOENT: no such file or directory, open 'C:\Users\scripting.filesystemobject\Deskto p\Default.aspx.html' at Error (native) the path should be C:\Users\scripting.filesystemobject\Deskto p\htmls\Default.aspx.html
PLR?PLRshould be in `` .