我有一个路径,其中有成千上万个文件夹,我只想在该路径下读取一个文件夹名称。如何使用Node.js从某个路径中仅获取一个文件夹(子目录)名称。我不想读取所有目录并读取返回数组的第0个索引,也不希望在读取一个元素后中断循环,因为这将不必要地加载成千上万个文件夹名称。
const fs = require('fs');
const fsPromise = fs.promises;
// inside some async function
/*
Next statement will return all the subdirectory in FOLDER_PATH,
which is say hundreds in some case.
But I'have to use only one of them. So why to fetch all and filter one?
*/
let subFolder = await fsPromise.readdir(FOLDER_PATH);
let oneFolder = subFolder[0]; // read 0 index out of all the folder list returned.
谢谢!