Skip to content

File.Readdir not supported #32

Description

@lordofscripts

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions