copy_dir

Function copy_dir 

Source
pub fn copy_dir(src: &Path, dst: &Path) -> Result<()>
Expand description

Recursively copies a directory and all its contents to a new location.

This function performs a deep copy of all files and subdirectories from the source to the destination. It creates the destination directory if it doesn’t exist and preserves the directory structure.

§Arguments

  • src - The source directory to copy from
  • dst - The destination directory to copy to

§Returns

  • Ok(()) if the directory was copied successfully
  • Err if the copy operation fails for any file or directory

§Examples

use agpm_cli::utils::fs::copy_dir;
use std::path::Path;

// Copy entire agent directory
copy_dir(Path::new("cache/agents"), Path::new("output/agents"))?;

§Behavior

  • Creates destination directory if it doesn’t exist
  • Recursively copies all subdirectories
  • Copies only regular files (skips symlinks and special files)
  • Overwrites existing files in the destination

§Platform Notes

  • Windows: Handles long paths and preserves attributes
  • Unix: Preserves file permissions during copy
  • All platforms: Does not follow symbolic links

§See Also