go语言获取系统盘符的方法
程序员文章站
2022-05-15 08:21:26
本文实例讲述了go语言获取系统盘符的方法。分享给大家供大家参考。具体如下:
涉及golang调用winapi获取系统盘符的技巧。代码如下:
复制代码 代码如下:// c...
本文实例讲述了go语言获取系统盘符的方法。分享给大家供大家参考。具体如下:
涉及golang调用winapi获取系统盘符的技巧。代码如下:
复制代码 代码如下:
// cs project main.go
package main
import (
"fmt"
. "strconv"
"syscall"
)
func getlogicaldrives() []string {
kernel32 := syscall.mustloaddll("kernel32.dll")
getlogicaldrives := kernel32.mustfindproc("getlogicaldrives")
n, _, _ := getlogicaldrives.call()
s := formatint(int64(n), 2)
var drives_all = []string{"a:", "b:", "c:", "d:", "e:", "f:", "g:", "h:", "i:", "j:", "k:", "l:", "m:", "n:", "o:", "p:", "q:", "r:", "s:", "t:", "u:", "v:", "w:", "x:", "y:", "z:"}
temp := drives_all[0:len(s)]
var d []string
for i, v := range s {
package main
import (
"fmt"
. "strconv"
"syscall"
)
func getlogicaldrives() []string {
kernel32 := syscall.mustloaddll("kernel32.dll")
getlogicaldrives := kernel32.mustfindproc("getlogicaldrives")
n, _, _ := getlogicaldrives.call()
s := formatint(int64(n), 2)
var drives_all = []string{"a:", "b:", "c:", "d:", "e:", "f:", "g:", "h:", "i:", "j:", "k:", "l:", "m:", "n:", "o:", "p:", "q:", "r:", "s:", "t:", "u:", "v:", "w:", "x:", "y:", "z:"}
temp := drives_all[0:len(s)]
var d []string
for i, v := range s {
if v == 49 {
l := len(s) - i - 1
d = append(d, temp[l])
}
}
var drives []string
for i, v := range d {
drives = append(drives[i:], append([]string{v}, drives[:i]...)...)
}
return drives
}
func main() {
fmt.println(getlogicaldrives())
}
希望本文所述对大家的go语言程序设计有所帮助。