跳到主要内容

create_dir

搜索

函数 create_dir 

Source
pub async fn create_dir(path: impl AsRef<Path>) -> Result<()>
展开描述

在提供的路径上创建一个新的空目录。

这是 std::fs::create_dir.

§Platform-specific behavior

此函数当前对应于 mkdir function on Unix and the CreateDirectory function on Windows. 请注意,此 将来可能会发生变化.

注意:如果给定路径的某个父目录不存在,此函数将 返回错误。若要同时创建目录及其所有缺失的父目录,请使用 create_dir_all 函数。

§Errors

在以下情况下此函数将返回错误,但不限于以下这些情况:

  • User lacks permissions to create directory at path.
  • A parent of the given path doesn’t exist. (To create a directory and all its missing parents at the same time, use the create_dir_all function.)
  • path already exists.

§示例

use tokio::fs;
use std::io;

#[tokio::main]
async fn main() -> io::Result<()> {
    fs::create_dir("/some/dir").await?;
    Ok(())
}