//getFileSize get file size by path(B)
func DirSizeB(path string) (int64, error) {
var size int64
err := filepath.Walk(path, func(_ string, info os.FileInfo, err error) error {
if !info.IsDir() {
size += info.Size()
}
return err
})
return size, err
}
//getFileSize get file size by path(B)
func getFileSize(path string) int64 {
if !exists(path) {
return 0
}
fileInfo, err := os.Stat(path)
if err != nil {
return 0
}
return fileInfo.Size()
}
//exists Whether the path exists
func exists(path string) bool {
_, err := os.Stat(path)
return err == nil || os.IsExist(err)
}
网友评论