diff --git a/pkg/utils/filesize.go b/pkg/utils/filesize.go index 8190577..8b5dd4b 100644 --- a/pkg/utils/filesize.go +++ b/pkg/utils/filesize.go @@ -2,6 +2,8 @@ package utils import ( "fmt" + "io/fs" + "path/filepath" "strconv" "strings" ) @@ -24,3 +26,21 @@ func ConvertFileSize(size int64) (float64, string, string) { return fSize, sizeSuffixes[idx], fmt.Sprint(fSizeStr, sizeSuffixes[idx]) } + +func DirectorySize(path string) (dirSz int64, err error) { + err = filepath.Walk(path, func(_ string, info fs.FileInfo, err error) error { + if err != nil { + return err + } + + dirSz += info.Size() + + return nil + }) + + if err != nil { + return dirSz, err + } + + return dirSz, nil +}