类:fs.Dir
🌐 Class: fs.Dir
表示目录流的类。
🌐 A class representing a directory stream.
由 fs.opendir()、fs.opendirSync() 或 fsPromises.opendir() 创建。
🌐 Created by fs.opendir(), fs.opendirSync(), or
fsPromises.opendir().
import { opendir } from 'node:fs/promises';
try {
const dir = await opendir('./');
for await (const dirent of dir)
console.log(dirent.name);
} catch (err) {
console.error(err);
} 使用异步迭代器时,<fs.Dir> 对象将在迭代器退出后自动关闭。
🌐 When using the async iterator, the <fs.Dir> object will be automatically closed after the iterator exits.