pub async fn metadata(path: impl AsRef<Path>) -> Result<Metadata>展开描述
给定一个路径,查询文件系统以获取有关文件、 目录等的信息。
此函数会遍历符号链接以查询目标文件的信息。
§Platform-specific behavior
此函数当前对应于 stat function on Unix and the
GetFileAttributesEx function on Windows. 请注意,此 may change in
the future.
§Errors
在以下情况下此函数将返回错误,但不限于以下这些情况:
- The user lacks permissions to perform
metadatacall onpath. pathdoes not exist.
§示例
use tokio::fs;
#[tokio::main]
async fn main() -> std::io::Result<()> {
let attr = fs::metadata("/some/file/path.txt").await?;
// inspect attr ...
Ok(())
}