In the Go language, to change the working directory using syscall – we use the Chdir() function of the syscallpackage. The Chdir() function is used to change the working directory.
Consider the below example demonstrating how to change the working directory using syscall in Golang?
package main
import (
"fmt"
"syscall"
)
func main() {
// Getting the current working directory
CurrentWD, _ := syscall.Getwd()
fmt.Println("CurrentWD:", CurrentWD)
// Changing the working directory
syscall.Chdir("/home/IncludeHelp/GoLang")
// Again,
// getting the current working directory
CurrentWD, _ = syscall.Getwd()
fmt.Println("CurrentWD:", CurrentWD)
}
Syntax:
Consider the below example demonstrating how to change the working directory using syscall in Golang?
Output
need an explanation for this answer? contact us directly to get an explanation for this answer