github.com/rosedblabs/rosedb/v2@v2.3.7-0.20240423093736-a89ea823e5b9/utils/file.go (about)

     1  package utils
     2  
     3  import (
     4  	"io/fs"
     5  	"path/filepath"
     6  )
     7  
     8  // DirSize get directory size
     9  func DirSize(dirPath string) (int64, error) {
    10  	var size int64
    11  	err := filepath.Walk(dirPath, func(path string, info fs.FileInfo, err error) error {
    12  		if err != nil {
    13  			return err
    14  		}
    15  		if !info.IsDir() {
    16  			size += info.Size()
    17  		}
    18  		return nil
    19  	})
    20  	return size, err
    21  }