pub fn ensure_parent_dir(path: &Path) -> Result<()>Expand description
Ensures that the parent directory of a file path exists.
This is a convenience function for creating the directory structure needed for a file before writing to it. It extracts the parent directory from the file path and ensures it exists.
§Arguments
path- The file path whose parent directory should exist
§Returns
Ok(())if the parent directory exists or was created successfullyErrif directory creation failsOk(())if the path has no parent (e.g., root level files)
§Examples
use agpm_cli::utils::fs::ensure_parent_dir;
use std::path::Path;
// Ensure directory structure exists before writing file
ensure_parent_dir(Path::new("output/agents/example.md"))?;
std::fs::write("output/agents/example.md", "# Example Agent")?;§Use Cases
- Preparing directory structure before file operations
- Ensuring atomic writes have proper directory structure
- Setting up output paths in batch processing
§See Also
ensure_dirfor creating a specific directoryatomic_writewhich calls this internally