"std:os/dir"Provides directory tree walking functionality inspired by Go's filepath.Walk. Uses runtime wrapper functions for directory operations.
View source on Codeberg →type Error int
Error represents an error code returned by directory operations.
type FileMode int
FileMode represents a file's mode and permission bits.
type FileInfo struct {
name string
size int
mode FileMode
modTime int
isDir bool
}
FileInfo describes a file and is returned by Stat and ReadDir.
type WalkFunc func(string, FileInfo, Error) Error
WalkFunc is the type of the function called by Walk to visit each file or directory. It receives the path, file info, and any error encountered visiting that path.
const (
OK Error = iota
ErrNotExist
ErrPerm
ErrNotDir
ErrIO
ErrInvalid
SkipDir
SkipAll
ErrNotSupported
)
Error constants for directory operations. OK indicates success. SkipDir causes Walk to skip the current directory. SkipAll causes Walk to stop walking entirely.
const (
ModeDir FileMode = 0x80000000
ModeRegular FileMode = 0
ModePerm FileMode = 0777
)
FileMode constants. ModeDir indicates a directory. ModeRegular indicates a regular file. ModePerm is the Unix permission bits mask.
func Stat(path string) (FileInfo, Error)
Returns the FileInfo for the named file or directory. Returns an error if the path does not exist or cannot be accessed.
func ReadDir(dirname string) (list[FileInfo], Error)
Reads the named directory and returns a list of FileInfo for its contents. Returns an error if the directory cannot be read.
func Walk(root string, walkFn WalkFunc) Error
Walks the file tree rooted at root, calling walkFn for each file or directory in the tree, including root. Errors visiting files are passed to walkFn for handling.
func Name(info FileInfo) string
Returns the base name of the file described by info.
func Size(info FileInfo) int
Returns the size in bytes of the file described by info.
func Mode(info FileInfo) FileMode
Returns the file mode bits of the file described by info.
func IsDir(info FileInfo) bool
Reports whether the file described by info is a directory.
func IsRegular(info FileInfo) bool
Reports whether the file described by info is a regular file.
func Perm(info FileInfo) FileMode
Returns the Unix permission bits of the file described by info.
func ModTime(info FileInfo) int
Returns the modification time of the file described by info as a Unix timestamp.