macro_rules! macro_create_directories {
    ( $( $_dir:expr ),* ) => { ... };
}
Expand description

§macro_create_directories Macro

Create multiple directories at once.

§Usage

use libmake::{macro_create_directories, macro_cleanup_directories};
use std::path::Path;
macro_create_directories!("logs", "logs1", "logs2");
macro_cleanup_directories!(Path::new("./logs"), Path::new("./logs1"), Path::new("./logs2"));

§Arguments

  • ... - Variable number of directory paths, each specified as an expression (expr).

§Behaviour

The macro_create_directories macro creates multiple directories at once. It takes a variable number of directory paths as arguments and uses the create_directory utility function from the $crate crate to create the directories.

The directories are specified as expressions and separated by commas. For example, macro_create_directories!("logs", "logs1", "logs2") will attempt to create the logs, logs1, and logs2.

The macro internally creates a slice of the directory paths and passes it to the create_directory function. If any error occurs during the directory creation, the macro returns an Err value, indicating the first encountered error. Otherwise, it returns Ok(()).

§Example

use libmake::{macro_create_directories, macro_cleanup_directories};
use std::path::Path;

fn main() -> Result<(), Box<dyn std::error::Error>> {
    let test = Path::new("logs");
    let test2  = Path::new("logs1");
    macro_create_directories!(test, test2)?;
    macro_cleanup_directories!(test, test2);
    Ok(())
}

§See Also

  • macro_check_directory for checking and creating a single directory
  • [macro_cleanup_directories] for cleaning up directories