Skip to main content

collect_files_recursive

Function collect_files_recursive 

Source
pub fn collect_files_recursive(
    dir: &Path,
    files: &mut Vec<PathBuf>,
) -> Result<()>
Expand description

Recursively collects all file paths within a directory.

Traverses a directory tree and compiles a list of all file paths found, excluding directories themselves.

§Arguments

  • dir - Reference to the directory to search
  • files - Mutable vector to store found file paths

§Returns

  • Ok(()) - If the collection process succeeds
  • Err - If any file system operation fails

§Examples

use std::path::{Path, PathBuf};
use ssg::collect_files_recursive;

fn main() -> anyhow::Result<()> {
    let mut files = Vec::new();
    let dir_path = Path::new("./examples/content");

    collect_files_recursive(dir_path, &mut files)?;

    for file in files {
        println!("Found file: {}", file.display());
    }

    Ok(())
}

§Note

This function:

  • Only collects file paths, not directory paths
  • Rejects symbolic links (consistent with security model)
  • Maintains original path structure