DirectorySize() func to get size of all files inside.
This commit is contained in:
parent
7ac1c2ccb9
commit
36b0dc7b4d
@ -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
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user