go语言获取系统盘符 go语言获取系统盘符的方法
无尽海 人气:0想了解go语言获取系统盘符的方法的相关内容吗,无尽海在本文为您仔细讲解go语言获取系统盘符的相关知识和一些Code实例,欢迎阅读和指正,我们先划重点:go语言,获取,系统盘符,方法,下面大家一起来学习吧。
本文实例讲述了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语言程序设计有所帮助。
加载全部内容