pub async fn create_dir_all(path: impl AsRef<Path>) -> Result<()>展开描述
递归创建一个目录及其所有缺失的父目录组件。
§Platform-specific behavior
此函数当前对应于 mkdir function on Unix
and the CreateDirectory function on Windows.
请注意,此 将来可能会发生变化.
§Errors
在以下情况下此函数将返回错误,但不限于以下这些情况:
- If any directory in the path specified by
pathdoes not already exist and it could not be created otherwise. The specific error conditions for when a directory is being created (after it is determined to not exist) are outlined byfs::create_dir.
Notable exception is made for situations where any of the directories
specified in the path 可能在并发创建时无法被创建。
此类情况视为成功。也就是说,调用
create_dir_all
从多个线程或进程并发调用保证不会因与自身的竞态条件而失败。
§示例
use tokio::fs;
#[tokio::main]
async fn main() -> std::io::Result<()> {
fs::create_dir_all("/some/dir").await?;
Ok(())
}