Function create_folder_for_file

Source
pub fn create_folder_for_file<P: AsRef<Path>>(path: P)
Expand description

Creates the parent folder for a file at the specified path if it does not already exist.

§Arguments

  • path - The path to the file for which the parent folder should be created (can be a &str, String, Path, or PathBuf).

§Panics

If some error is encountered while creating the parent folder.

§Examples

§Using a string literal

use file_io::create_folder_for_file;
     
let path: &str = "folder/subfolder_3/file_1.txt";

// This will create "folder/subfolder_3" if it does not exist.
create_folder_for_file(path);

§Using a Path reference

use file_io::create_folder_for_file;
use std::path::Path;

let path: &Path = Path::new("folder/subfolder_4/file_2.txt");

// This will create "folder/subfolder_4" if it does not exist.
create_folder_for_file(path);