Golang : get the current working directory of a running program
Problem :
You are looking for way to get the folder/directory of the running program.
Solution :
Use https://bitbucket.org/kardianos/osext ExecutableFolder()
function. For example :
package main
import (
"bitbucket.org/kardianos/osext"
"fmt"
)
func main() {
// get the current folder of the running program
path, err := osext.ExecutableFolder()
if err != nil {
fmt.Println(err)
}
fmt.Println("Program is executing at folder :", path)
}
Sample output :
go run executabledir.go
Program is executing at folder : /tmp/go-build113823238/command-line-arguments/_obj/exe/
See also : Golang : Get current file path of a file or executable
By Adam Ng
IF you gain some knowledge or the information here solved your programming problem. Please consider donating to the less fortunate or some charities that you like. Apart from donation, planting trees, volunteering or reducing your carbon footprint will be great too.
Advertisement
Tutorials
+12.9k Swift : Convert (cast) Int to String ?
+5.5k Python : Print unicode escape characters and string
+4.7k Linux/MacOSX : How to symlink a file?
+9.2k Golang : Create and shuffle deck of cards example
+7.3k Golang : Accessing dataframe-go element by row, column and name example
+21.2k Golang : Create and resolve(read) symbolic links
+6k PageSpeed : Clear or flush cache on web server
+7k Javascript : How to get JSON data from another website with JQuery or Ajax ?
+7.3k Golang : Check to see if *File is a file or directory
+4.2k Golang : Converting individual Jawi alphabet to Rumi(Romanized) alphabet example
+12.8k Golang : http.Get example
+11.1k Golang : Fix - does not implement sort.Interface (missing Len method)