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.8k Elastic Search : Mapping date format and sort by date
+4.5k Javascript : Shuffle or randomize array example
+6.4k Javascript : Push notifications to browser with Push.js
+11.2k Golang : Listen and Serve on sub domain example
+10.5k Golang : Sort and reverse sort a slice of runes
+10.5k CodeIgniter : Import Linkedin data
+5.6k Golang : Gargish-English language translator
+5.5k Unix/Linux : Use netstat to find out IP addresses served by your website server
+6.5k SSL : How to check if current certificate is sha1 or sha2 from command line
+15.5k Golang : Merge video(OpenCV) and audio(PortAudio) into a mp4 file
+17.9k Golang : Check if directory exist and create if does not exist
+22.1k Golang : Fix type interface{} has no field or no methods and type assertions example