go: github.com/shurcooL/go/vfs/godocfs/vfsutil Index | Examples | Files

package vfsutil

import "github.com/shurcooL/go/vfs/godocfs/vfsutil"

Package vfsutil implements some I/O utility functions for vfs.FileSystem.

Index

Examples

Package Files

walk.go

func Walk Uses

func Walk(fs vfs.FileSystem, root string, walkFn filepath.WalkFunc) error

Walk walks the filesystem rooted at root, calling walkFn for each file or directory in the filesystem, including root. All errors that arise visiting files and directories are filtered by walkFn. The files are walked in lexical order.

Code:

var fs vfs.FileSystem = mapfs.New(map[string]string{
    "zzz-last-file.txt":   "It should be visited last.",
    "a-file.txt":          "It has stuff.",
    "another-file.txt":    "Also stuff.",
    "folderA/entry-A.txt": "Alpha.",
    "folderA/entry-B.txt": "Beta.",
})

walkFn := func(path string, fi os.FileInfo, err error) error {
    if err != nil {
        log.Printf("can't stat file %s: %v\n", path, err)
        return nil
    }
    fmt.Println(path)
    return nil
}

err := vfsutil.Walk(fs, "/", walkFn)
if err != nil {
    panic(err)
}

Output:

/
/a-file.txt
/another-file.txt
/folderA
/folderA/entry-A.txt
/folderA/entry-B.txt
/zzz-last-file.txt

Package vfsutil imports 5 packages (graph) and is imported by 6 packages. Updated 2016-07-21. Refresh now. Tools for package owners.