Created
November 6, 2018 07:11
-
-
Save brydavis/c599fa1ef981d8dc6d3aef3b5cc208c1 to your computer and use it in GitHub Desktop.
recursively measuring the size of the a directory / subdirectory
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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