×

Golang Tutorial

Golang Reference

Golang Programs

Golang Practice

Golang Miscellaneous

How to get the working directory using syscall in Golang?

Here, we will learn to get the working directory using syscall in Golang.
Submitted by IncludeHelp, on November 13, 2021 [Last updated : March 05, 2023]

Getting the working directory using syscall in Golang

In the Go programming language, to get the working directory using syscall – we use the Getwd() function of the syscall package. The Getwd() function returns the working directory.

Syntax

func Getwd() (wd string, err error)

Consider the below example demonstrating how to get the working directory using syscall in Golang?

Golang code to get the working directory using syscall

package main

import (
	"fmt"
	"syscall"
)

func main() {
	// Using the Getwd(),
	// Getting the working directory
	wd,_ := syscall.Getwd()

	// Printing the working directory
	fmt.Println("Working directory:", wd)
}

Output

Working directory: /home

Golang syscall Package Programs »





Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.