I was trying to get the size of directories. But since ReadDir (uppercase D) doesn't allow us to access the size, we have to use the File.Readdir() from the File object returned by VFS.Open(). Notice that the latter is Readdir with lowercase D.
So, removing all error checking for simplicity:
func GetDirSize(directory string) int64 {
dirRead, err := os.Open(directory)
dirFiles, err := dirRead.Readdir(0)
sum := int64(0)
for _, fi := range dirFiles {
sum += fi.Size()
}
dirRead.Close()
return sum
}
By the way, it appears ReadDir() with uppercase Dir is also not supported.
I was trying to get the size of directories. But since
ReadDir(uppercase D) doesn't allow us to access the size, we have to use theFile.Readdir()from theFileobject returned byVFS.Open(). Notice that the latter isReaddirwith lowercase D.So, removing all error checking for simplicity:
By the way, it appears
ReadDir()with uppercaseDiris also not supported.