rust 创建文件夹 容错

180it 2024-10-23 AM 138℃ 0条
use std::fs;
use std::io::Error;

fn create_folder(path: &str) -> Result<(), Error> {
    match fs::create_dir_all(path) {
        Ok(_) => {
            println!("文件夹创建成功: {}", path);
            Ok(())
        }
        Err(e) => {
            eprintln!("创建文件夹失败: {} - 错误: {}", path, e);
            Err(e)
        }
    }
}

fn main() -> Result<(), Error> {
    let folder_path = "path/to/your/folder";
    create_folder(folder_path)?;

    Ok(())
}
支付宝打赏支付宝打赏 微信打赏微信打赏

如果文章或资源对您有帮助,欢迎打赏作者。一路走来,感谢有您!

标签: none

rust 创建文件夹 容错