所以我试图使用golang获取目录的总大小,到目前为止我有这个
- var dirSize int64 = 0
- func readSize(path string,file os.FileInfo,err error) error {
- if !file.IsDir() {
- dirSize += file.Size()
- }
- return nil
- }
- func DirSizeMB(path string) float64 {
- dirSize = 0
- filepath.Walk(path,readSize)
- sizeMB := float64(dirSize) / 1024.0 / 1024.0
- sizeMB = Round(sizeMB,.5,2)
- return sizeMB
- }