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
+10.1k CodeIgniter : Load different view for mobile devices
+10.8k Golang : Get currencies exchange rates example
+8.4k Golang : Number guessing game with user input verification example
+5.1k Golang : Constant and variable names in native language
+18k Golang : Iterate linked list example
+24.1k Golang : Use regular expression to validate domain name
+24.2k Golang : Upload to S3 with official aws-sdk-go package
+9.5k Golang : Timeout example
+9.9k Golang : Qt get screen resolution and display on center example
+8.7k Golang : Add text to image and get OpenCV's X, Y co-ordinates example
+23.1k Golang : Calculate time different
+16.5k CodeIgniter/PHP : Create directory if does not exist example