fs.Dir 类
表示目录流的类。
由 fs.opendir()
、fs.opendirSync()
或 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> 对象将在迭代器退出后自动关闭。
A class representing a directory stream.
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);
}
When using the async iterator, the <fs.Dir> object will be automatically closed after the iterator exits.