简体   繁体   English

go以编程方式查找当前工作目录?

[英]Finding the current working directory programmatically in go?

I have been looking trough the go documentation but so far I haven't found anything. 我一直在寻找go go文档,但到目前为止我还没有找到任何东西。 I need help to find the current working directory programmaticly in go language. 我需要帮助以go语言编程方式查找current working directory Does any one know how to do that? 有谁知道这是怎么做到的吗?

Getwd from the os package will return your current working directory. 来自os包的Getwd将返回当前的工作目录。 For more operating system related functions look in the os package. 有关更多与操作系统相关的功能,请查看os包。

If you want to print it do the following. 如果要打印,请执行以下操作。

import (
    "fmt"
    "os"
)

func main() {
    wd, _ := os.Getwd()
    fmt.Println("Working Directory:", wd)
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Go 错误:go:go.mod 文件未在当前目录或任何父目录中找到; (在 GOPATH/src 上工作) - Go error: go : go.mod file not found in current directory or any parent directory; (working on GOPATH/src) 如何在 Go 中更改 shell 的当前工作目录? - How to change the shell's current working directory in Go? 如何在 Go 中更改当前目录 - How to change the current directory in Go 如何从 go 的当前目录导入文件 - How to import files from current directory in go 转到-遍历当前目录中的Directores /文件 - Go - Iterate through directores/files in current directory 错误信息:go: go.mod 文件在当前目录或任何父目录中找不到; - Error Message : go: go.mod file not found in current directory or any parent directory; “去:go.mod 文件在当前目录中找不到”但它已经存在于目录中 - "go: go.mod file not found in current directory" but it already exist in the directory Docker 构建:“go:在当前目录或任何父目录中找不到 go.mod 文件” - Docker build : "go: go.mod file not found in current directory or any parent directory" 错误消息“转到:go.mod 文件在当前目录或任何父目录中找不到;请参阅“转到帮助模块”” - Error message "go: go.mod file not found in current directory or any parent directory; see 'go help modules'" 如何获取文件所在的 package 目录,而不是当前工作目录 - How to get the directory of the package the file is in, not the current working directory
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM