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?
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's not a system-controlled environment variable.