zerolaunch_plugin_api/common/
dir_utils.rs1use std::fs;
2use std::io;
3use std::path::Path;
4
5pub struct DirUtils;
8
9impl DirUtils {
10 pub fn read_dir_or_create<P: AsRef<Path>>(path: P) -> Result<fs::ReadDir, String> {
14 match fs::read_dir(&path) {
15 Ok(dir) => Ok(dir),
16 Err(e) if e.kind() == io::ErrorKind::NotFound => {
17 fs::create_dir_all(&path).map_err(|e| format!("无法创建目录: {}", e))?;
18 fs::read_dir(path).map_err(|e| format!("无法读取新创建的目录: {}", e))
19 }
20 Err(e) => Err(format!("无法读取目录: {}", e)),
21 }
22 }
23}