How do you get a list of the names of all files present in a directory in Node.js?

后端 未结 25 1241
天涯浪人
天涯浪人 2020-11-22 07:47

I\'m trying to get a list of the names of all the files present in a directory using Node.js. I want output that is an array of filenames. How can I do this?

25条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-11-22 08:36

    This will work and store the result in test.txt file which will be present in the same directory

      fs.readdirSync(__dirname).forEach(file => {
        fs.appendFileSync("test.txt", file+"\n", function(err){
        })
    })
    

提交回复
热议问题