Skip to content

Instantly share code, notes, and snippets.

@223n
Created May 24, 2017 13:58
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 223n/55ae071918dbea96c65e9eed0b69856e to your computer and use it in GitHub Desktop.
Save 223n/55ae071918dbea96c65e9eed0b69856e to your computer and use it in GitHub Desktop.
Goで指定したフォルダのサイズを求めようとしていた
package main
import (
"fmt"
"os"
"path/filepath"
)
func main() {
value, _ := DirSize("\\\\nas1101\\Users")
fmt.Println(value)
}
func DirSize(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
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment