github.com/Azareal/Gosora@v0.0.0-20210729070923-553e66b59003/common/disk.go (about) 1 package common 2 3 import ( 4 "path/filepath" 5 "os" 6 ) 7 8 func DirSize(path string) (int, error) { 9 var size int64 10 err := filepath.Walk(path, func(_ string, file os.FileInfo, err error) error { 11 if err != nil { 12 return err 13 } 14 if !file.IsDir() { 15 size += file.Size() 16 } 17 return err 18 }) 19 return int(size), err 20 }