Struct std::fs::DirEntry 1.0.0[−][src]
pub struct DirEntry(_);
Expand description
ReadDir
迭代器返回的条目。
DirEntry
的实例表示文件系统上目录内的一个条目。
可以通过方法检查每个条目,以通过全平台扩展 traits 了解完整路径或可能的其他元数据。
Implementations
返回此条目指向的文件的元数据。
如果此函数指向符号链接,则该函数将不会遍历符号链接。要遍历符号链接,请使用 fs::metadata
或 fs::File::metadata
。
特定于平台的行为
在 Windows 上,此函数的调用很便宜 (不需要额外的系统调用),但是在 Unix 平台上,此函数等效于在路径上调用 symlink_metadata
。
Examples
use std::fs;
if let Ok(entries) = fs::read_dir(".") {
for entry in entries {
if let Ok(entry) = entry {
// 在此,`entry` 是 `DirEntry`。
if let Ok(metadata) = entry.metadata() {
// 现在,让我们显示条目的权限!
println!("{:?}: {:?}", entry.path(), metadata.permissions());
} else {
println!("Couldn't get metadata for {:?}", entry.path());
}
}
}
}
Run返回此条目指向的文件的文件类型。
如果此函数指向符号链接,则该函数将不会遍历符号链接。
特定于平台的行为
在 Windows 和大多数 Unix 平台上,此函数是免费的 (不需要额外的系统调用),但是某些 Unix 平台可能需要与 symlink_metadata
等效的调用才能了解目标文件类型。
Examples
use std::fs;
if let Ok(entries) = fs::read_dir(".") {
for entry in entries {
if let Ok(entry) = entry {
// 在此,`entry` 是 `DirEntry`。
if let Ok(file_type) = entry.file_type() {
// 现在,让我们显示条目的文件类型!
println!("{:?}: {:?}", entry.path(), file_type);
} else {
println!("Couldn't get file type for {:?}", entry.path());
}
}
}
}
Run