How to Copy and Move Files in Rust

Use std::fs::copy to duplicate files and std::fs::rename to move them in Rust.

Use std::fs::copy to duplicate a file and std::fs::rename to move it, handling errors with unwrap or match.

use std::fs;

fn main() -> std::io::Result<()> {
    // Copy file
    fs::copy("source.txt", "dest.txt")?;
    
    // Move file (renames source to dest)
    fs::rename("source.txt", "moved.txt")?;
    
    Ok(())
}