Overview
os.Chdir() is used to change the current working directory to the named directory in golang. It is similar to the cd command.
Below is the signature of the function
func Chdir(dir string) error
Code
package main
import (
"fmt"
"os"
)
func main() {
os.Chdir("/Users")
newDir, err := os.Getwd()
if err != nil {
}
fmt.Printf("Current Working Direcotry: %s\n", newDir)
}
Output:
Current Working Direcoty: /Users