Get the Current Working Directory in Rust

September 2025
use std::env;

fn main() -> std::io::Result<()> {
    let path = env::current_dir()?;
    println!("The current directory is {}", path.display());
    Ok(())
}
Output:
The current directory is /Users/alan/workshop/examples
end of line