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

后端 未结 25 1678
天涯浪人
天涯浪人 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条回答
  •  春和景丽
    2020-11-22 08:28

    I usually use: FS-Extra.

    const fileNameArray = Fse.readdir('/some/path');
    

    Result:

    [
      "b7c8a93c-45b3-4de8-b9b5-a0bf28fb986e.jpg",
      "daeb1c5b-809f-4434-8fd9-410140789933.jpg"
    ]
    

提交回复
热议问题