vfs icon indicating copy to clipboard operation
vfs copied to clipboard

File.Readdir not supported

Open lordofscripts opened this issue 1 year ago • 1 comments

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.

lordofscripts avatar Aug 24 '24 21:08 lordofscripts

Hopefully this project gets updated because it has no external dependencies. The others I have examined have a large footprint.

lordofscripts avatar Aug 24 '24 22:08 lordofscripts