1
0

DirectorySize() func to get size of all files inside.

This commit is contained in:
Alexander Andreev 2022-02-07 22:17:40 +04:00
parent 7ac1c2ccb9
commit 36b0dc7b4d
Signed by: Arav
GPG Key ID: 1327FE8A374CC86F

View File

@ -2,6 +2,8 @@ package utils
import ( import (
"fmt" "fmt"
"io/fs"
"path/filepath"
"strconv" "strconv"
"strings" "strings"
) )
@ -24,3 +26,21 @@ func ConvertFileSize(size int64) (float64, string, string) {
return fSize, sizeSuffixes[idx], fmt.Sprint(fSizeStr, sizeSuffixes[idx]) 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
}