Q:

How to change the working directory using syscall in Golang?

belongs to collection: Golang syscall Package Programs

0

In the Go language, to change the working directory using syscall – we use the Chdir() function of the syscall package. The Chdir() function is used to change the working directory.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Syntax:

func Chdir(path string) (err error)

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)
}

Output

CurrentWD: /home
CurrentWD: /home/IncludeHelp/GoLang

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

How to get the disk usage information in Golang?... >>
<< How to convert a string to a byte slice in Golang?...