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
+15.8k Golang : Get file permission
+9.4k Golang : Eroding and dilating image with OpenCV example
+7.9k Golang : Routes multiplexer routing example with regular expression control
+8k Golang : HttpRouter multiplexer routing example
+17k Golang : When to use init() function?
+10.4k Golang : Bubble sort example
+5.5k Golang : ROT32768 (rotate by 0x80) UTF-8 strings example
+16.4k Golang : Read integer from file into array
+6.6k Mac OSX : Find large files by size
+7.9k Golang : Randomize letters from a string example
+15.8k Golang : Get sub string example
+10.2k Android Studio : Simple input textbox and intercept key example