Friday 24 May 2019

Question - fs.readdir() leaves files open - how can I close them?

When looping through some directories using fs.readdir() at some point I get the following error message:Error: EMFILE: too many open files, open 'myfile.txt'Emitted 'error' event at:at lazyFs.open (internal/fs/streams.js:115:12)at FSReqWrap.args [as oncomplete] (fs.js:140:20)I assume this is because I do not do fs.close(fd) on these files, since I do not get the option with fs.readdir() to set a file descriptor for every file I loop through in a directory.How can I close the files I have already looped through? I really can't afford to manually open all files one by one using fs.open() .Thanks for any tips or hints in the right direction. I use fs.stat() and lineReader from the linereader interface to read the first line of each file, because I only need to check the content of the first line.

Submitted May 24, 2019 at 03:34PM by Exploree1

No comments:

Post a Comment