diskutils

package
v0.0.0-...-98f1bff Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 13, 2025 License: Unlicense Imports: 1 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DiskInfo

type DiskInfo struct {
	Path      string  // 挂载点路径
	Total     uint64  // 总大小(字节)
	Free      uint64  // 可用空间(字节)
	Used      uint64  // 已用空间(字节)
	UsedRatio float64 // 使用率百分比
}

DiskInfo 磁盘信息

func GetDiskInfo

func GetDiskInfo(path string) (*DiskInfo, error)

GetDiskInfo 获取指定路径磁盘信息

Example

ExampleGetDiskInfo 展示如何使用GetDiskInfo函数

// 获取根目录的磁盘信息
diskInfo, err := GetDiskInfo("/")
if err != nil {
	fmt.Printf("获取磁盘信息失败: %v\n", err)
	return
}

// 打印磁盘信息
fmt.Printf("路径: %s\n", diskInfo.Path)
fmt.Printf("总空间: %.2f GB\n", float64(diskInfo.Total)/1e9)
fmt.Printf("已用空间: %.2f GB\n", float64(diskInfo.Used)/1e9)
fmt.Printf("可用空间: %.2f GB\n", float64(diskInfo.Free)/1e9)
fmt.Printf("使用率: %.2f%%\n", diskInfo.UsedRatio)

// 输出不确定,所以不做验证

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL