mirror of
https://github.com/XZB-1248/Spark
synced 2025-10-10 18:30:07 +08:00
32 lines
778 B
Go
32 lines
778 B
Go
//go:build windows
|
|
// +build windows
|
|
|
|
package file
|
|
|
|
import "github.com/shirou/gopsutil/v3/disk"
|
|
|
|
// ListFiles will only be called when path is root and
|
|
// current system is Windows.
|
|
// It will return mount points of all volumes.
|
|
func ListFiles(path string) ([]File, error) {
|
|
result := make([]File, 0)
|
|
if len(path) == 0 || path == `\` || path == `/` {
|
|
partitions, err := disk.Partitions(true)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
for i := 0; i < len(partitions); i++ {
|
|
size := uint64(0)
|
|
stat, err := disk.Usage(partitions[i].Mountpoint)
|
|
if err != nil || stat == nil {
|
|
size = 0
|
|
} else {
|
|
size = stat.Total
|
|
}
|
|
result = append(result, File{Name: partitions[i].Mountpoint, Type: 2, Size: size})
|
|
}
|
|
return result, nil
|
|
}
|
|
return listFiles(path)
|
|
}
|