To get the current working directory using the os package in Go, you can use the Getwd()
function, which returns a string containing the path of the current working directory. Here's an example code snippet:
main.go249 chars16 lines
In this example, we import the fmt
and os
packages, then use the Getwd()
function to get the current working directory. We use the if err != nil
construct to check if any error occurred while getting the directory, and print the error message if there was one. Finally, we print the current working directory to the console using fmt.Println()
.
gistlibby LogSnag