2

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

5
  • 1
    should const ext = path.extname(files) be const ext = path.extname(f)? Commented Apr 22, 2016 at 8:03
  • My mistake. But problem remains. Commented Apr 22, 2016 at 8:43
  • sorry what is PLR? Commented Apr 22, 2016 at 8:56
  • how are you running the application and in which directory ? PLR should be in `` . Commented Apr 22, 2016 at 9:02
  • It is catching the path of plr which is on desktop the same folder as ttst.js file. However while readFile omits the \plr\ Commented Apr 22, 2016 at 11:50

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.