Open
Description
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.
Metadata
Metadata
Assignees
Labels
No labels