cd command Archives - Welcome To Golang By Example https://vikasboss.github.io/tag/cd-command/ Sat, 18 Apr 2020 05:47:57 +0000 en-US hourly 1 https://wordpress.org/?v=6.8.1 https://i0.wp.com/golangbyexamples.com/wp-content/uploads/2021/05/cropped-go_border-1.png?fit=32%2C32&ssl=1 cd command Archives - Welcome To Golang By Example https://vikasboss.github.io/tag/cd-command/ 32 32 159787465 cd command in Go or change current working directory in Go (Golang) https://vikasboss.github.io/change-current-working-directory-go/ https://vikasboss.github.io/change-current-working-directory-go/#respond Fri, 17 Apr 2020 20:40:12 +0000 https://vikasboss.github.io/?p=2053 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 Code Output:

The post cd command in Go or change current working directory in Go (Golang) appeared first on Welcome To Golang By Example.

]]>
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

The post cd command in Go or change current working directory in Go (Golang) appeared first on Welcome To Golang By Example.

]]>
https://vikasboss.github.io/change-current-working-directory-go/feed/ 0 2053