Skip to content

Instantly share code, notes, and snippets.

@brydavis
Created November 6, 2018 07:11
Show Gist options
  • Save brydavis/c599fa1ef981d8dc6d3aef3b5cc208c1 to your computer and use it in GitHub Desktop.
Save brydavis/c599fa1ef981d8dc6d3aef3b5cc208c1 to your computer and use it in GitHub Desktop.
recursively measuring the size of the a directory / subdirectory
package main
import "filepath"
import "os"
func main() {
dirSize("path/to/folder")
}
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