What is the file extension if the filename has more than one dots in them?

extension

I had a bug in one of my applications so I was wondering what happens if a filename has more than one dot in them. e.g. "hello.world.txt" Will the extension method return txt as I'd expect?

The answer is: yes.

My bug is somewhere else.

examples/extenstion-for-files-with-dot/src/main.rs

use std::path::PathBuf;
fn main() {
    let path = PathBuf::from("code.rs");
    println!("{:?} {:?}", path, path.extension().unwrap());

    let path = PathBuf::from("my-data-1.70.html");
    println!("{:?} {:?}", path, path.extension().unwrap());
}

"code.rs" "rs"
"my-data-1.70.html" "html"

Author

Gabor Szabo (szabgab)

Gabor Szabo, the author of the Rust Maven web site maintains several Open source projects in Rust and while he still feels he has tons of new things to learn about Rust he already offers training courses in Rust and still teaches Python, Perl, git, GitHub, GitLab, CI, and testing.

Gabor Szabo