2016-12-21 03:07
浏览 642

如何在Google Golang中获取Windows的系统根目录?

Under Windows, the system root directory could be like C:// or D:// (when the OS is installed in driver D:/). How to get this folder in Go?

图片转代码服务由CSDN问答提供 功能建议

在Windows下,系统根目录可能类似于 C:// D:// (当操作系统安装在驱动程序 D:/ 中时)。 如何在Go中获取此文件夹?

  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • doubi4340 2016-12-21 03:46

    You could use filepath.VolumeName(os.GetEnv("SYSTEMROOT")) + "\\" or the shorter os.GetEnv("SYSTEMDRIVE") + "\\". The windir environment variable probably shouldn't be used anymore honestly since it is not a system-controlled environment variable.

    Source for the mentioned environment variables

    打赏 评论
  • dongluo8303 2016-12-21 03:42

    You may use os.Getenv to get the value for "environment" variable windir. An example is below:

    package main
    import "os"
    import "fmt"
    func main() {
        fmt.Println("system dir: ", os.Getenv("windir"))
    打赏 评论

相关推荐 更多相似问题