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
+7.9k Golang : How to get username from email address
+10.6k Golang : Convert(cast) float to int
+36.5k Golang : Comparing date or timestamp
+11.2k Golang : Validate email address
+20.2k SSL : How to check if current certificate is sha1 or sha2
+8.9k Golang : Compare files modify date example
+7.2k Your page has meta tags in the body instead of the head
+8.7k Golang : Identifying Golang HTTP client request
+12.8k Golang : Simple word wrap or line breaking example
+5.2k Golang : Join lines with certain suffix symbol example
+21.2k Golang : Round float to precision example
+12.4k Golang : Query string with space symbol %20 in between