deoren / notes

Various notes for topics I'm learning
2 stars 0 forks source link

Get the directory of the currently running file #76

Open deoren opened 5 years ago

deoren commented 5 years ago

https://stackoverflow.com/questions/18537257/how-to-get-the-directory-of-the-currently-running-file

package main

import (
    "fmt"
    "os"
    "path/filepath"
)

func main() {
    ex, err := os.Executable()
    if err != nil {
        panic(err)
    }
    exPath := filepath.Dir(ex)
    fmt.Println(exPath)
}