Logo

Programming-Idioms

  • Rust
  • Ruby
s = __FILE__
s = $0

Unfortunately, s includes the path given to the interpreter, not just the .rb program name.
let s = std::env::current_exe()
    .expect("Can't get the exec path")
    .file_name()
    .expect("Can't get the exec name")
    .to_string_lossy()
    .into_owned();
fn get_exec_name() -> Option<String> {
    std::env::current_exe()
        .ok()
        .and_then(|pb| pb.file_name().map(|s| s.to_os_string()))
        .and_then(|s| s.into_string().ok())
}

fn main() -> () {
    let s = get_exec_name().unwrap();
    println!("{}", s);
}
with Ada.Command_Line; use Ada.Command_Line;
with Ada.Directories; use Ada.Directories;
S : String := (Simple_Name (Command_Name));

New implementation...
< >
programming-idioms.org