Skip to content

File.Readdir not supported #32

Open
@lordofscripts

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.

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