use std::fs;
use std::io;
use std::path::Path;
pub struct DirUtils;
impl DirUtils {
pub fn read_dir_or_create<P: AsRef<Path>>(path: P) -> Result<fs::ReadDir, String> {
match fs::read_dir(&path) {
Ok(dir) => Ok(dir),
Err(e) if e.kind() == io::ErrorKind::NotFound => {
fs::create_dir_all(&path).map_err(|e| format!("无法创建目录: {}", e))?;
fs::read_dir(path).map_err(|e| format!("无法读取新创建的目录: {}", e))
}
Err(e) => Err(format!("无法读取目录: {}", e)),
}
}
}