Function nix::unistd::mkdir

source ·
pub fn mkdir<P: ?Sized + NixPath>(path: &P, mode: Mode) -> Result<()>
Expand description

Creates new directory path with access rights mode. (see mkdir(2))

Errors

There are several situations where mkdir might fail:

  • current user has insufficient rights in the parent directory
  • the path already exists
  • the path name is too long (longer than PATH_MAX, usually 4096 on linux, 1024 on OS X)

Example

use nix::unistd;
use nix::sys::stat;
use tempfile::tempdir;

let tmp_dir1 = tempdir().unwrap();
let tmp_dir2 = tmp_dir1.path().join("new_dir");

// create new directory and give read, write and execute rights to the owner
match unistd::mkdir(&tmp_dir2, stat::Mode::S_IRWXU) {
   Ok(_) => println!("created {:?}", tmp_dir2),
   Err(err) => println!("Error creating directory: {}", err),
}