Golang : Get path name to current directory or folder
Problem :
You need to get the path name of the current directory where the executable is residing. How to do that in Golang?
Solution :
Use the os.Getwd()
function.
For example :
package main
import (
"fmt"
"os"
"strings"
)
func main() {
dir, _ := os.Getwd()
fmt.Println(strings.Replace(dir, " ", "\\ ", -1))
}
UPDATE : This is similar to the Linux/Unix command pwd
-- return working directory name.
See also : Golang : get the current working directory of a running program
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
+9k Golang : Apply Histogram Equalization to color images
+12.8k Golang : Convert(cast) uintptr to string example
+5.1k Golang : Pad file extension automagically
+50.5k Golang : Disable security check for HTTPS(SSL) with bad or expired certificate
+4.4k Mac OSX : Get disk partitions' size, type and name
+30.6k error: trying to remove "yum", which is protected
+15.3k Golang : Intercept Ctrl-C interrupt or kill signal and determine the signal type
+8.9k Android Studio : Indicate progression with ProgressBar example
+9.4k Javascript : Read/parse JSON data from HTTP response
+34.3k Golang : Smarter Error Handling with strings.Contains()
+30.5k Golang : Download file example