类:fs.Dirent
🌐 Class: fs.Dirent
目录项的表示,可以是目录中的文件或子目录,由从 <fs.Dir> 读取时返回。目录项是文件名和文件类型的组合。
🌐 A representation of a directory entry, which can be a file or a subdirectory within the directory, as returned by reading from an <fs.Dir>. The directory entry is a combination of the file name and file type pairs.
此外,当调用 fs.readdir() 或 fs.readdirSync() 并将 withFileTypes 选项设置为 true 时,返回的数组将填充 <fs.Dirent> 对象,而不是字符串或 <Buffer>。
🌐 Additionally, when fs.readdir() or fs.readdirSync() is called with
the withFileTypes option set to true, the resulting array is filled with
<fs.Dirent> objects, rather than strings or <Buffer>s.
当读取一个目录时,比如使用 fs.readdir() 或 fs.opendir(),每个条目的文件类型都是操作系统报告的类型,并且可能取决于文件系统;例如,一些文件系统可能报告的类型与 fs.lstat() 返回的类型不同。只有当报告的类型未知时,Node.js 才会对这样的条目调用 fs.lstat()。当需要准确的文件类型时,请使用 fs.lstat()。
🌐 When a directory is read, such as with fs.readdir() or
fs.opendir(), the file type of each entry is the type reported by the
operating system and may depend on the file system; for example, some file
systems may report a type that differs from what fs.lstat() returns.
Node.js calls fs.lstat() on such an entry only when the reported type
is unknown. Use fs.lstat() when an accurate file type is required.