diskusage_windows.go 509 B

123456789101112131415161718
  1. //go:build windows
  2. package capability
  3. import "golang.org/x/sys/windows"
  4. // DiskUsage returns the free and total bytes of the volume holding path.
  5. func DiskUsage(path string) (free int64, total int64, err error) {
  6. p, err := windows.UTF16PtrFromString(path)
  7. if err != nil {
  8. return 0, 0, err
  9. }
  10. var freeAvail, totalBytes, totalFree uint64
  11. if err := windows.GetDiskFreeSpaceEx(p, &freeAvail, &totalBytes, &totalFree); err != nil {
  12. return 0, 0, err
  13. }
  14. return int64(freeAvail), int64(totalBytes), nil
  15. }