Logo

Programming-Idioms

  • Go
  • C
#include <string.h>
#ifdef _WIN32
#define PATH_SEP '\\'
#else
#define PATH_SEP '/'
#endif

int main(int argc, char* argv[])
{
    char *s = strchr(argv[0], PATH_SEP);
    s = s ? s + 1 : argv[0];

    return 0;
}
import "os"
import "path/filepath"
path := os.Args[0]
s = filepath.Base(path)

The program path is its "0th argument".
import (
  "os"
  "path/filepath"
)
path, err := os.Executable()
if err != nil {
  panic(err)
}
s = filepath.Base(path)

Executable function is supported since 1.8
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