Goで指定したフォルダのサイズを求めようとしていた
This file contains 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 ( | |
"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