walk

package module
v1.2.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 26, 2025 License: MIT Imports: 6 Imported by: 3

README

README

A Go package for efficient directory traversal and file listing, with flexible depth control and exclusion options.

Supports both OS-native traversal and fast index-based search using Everything (Windows only).

Features

  • Traverse directory trees from a specified root.
  • Optionally include files, directories, or both.
  • Control the maximum traversal depth.
  • Exclude specified directory or file names.
  • Two traversal backends:
    • Standard Go filesystem walk (filepath.WalkDir)
    • Fast search via Everything (if available, Windows only)
Example
w := &walk.Walker{}
w.Init("C:\\Users\\YourName", false, 2, "node_modules,.git")

// OS-native traversal
found, err := w.Traverse()
if err != nil {
    log.Fatal(err)
}
fmt.Println("Found:", found)

// Everything-based traversal (Windows, Everything required)
found2, err := w.EverythingTraverse()
if err != nil {
    log.Fatal(err)
}
fmt.Println("Found (Everything):", found2)

API

func (w *Walker) Init(root string, all bool, depth int, exclude string)

Initializes the walker.

  • root: Root directory to start traversal.
  • all: If true, include files and directories. If false, include only directories.
  • depth: Maximum traversal depth (-1 for unlimited).
  • exclude: Comma-separated list of directory/file names to exclude.
func (w Walker) Traverse() ([]string, error)

Traverse the filesystem using Go's standard library.

Returns a list of paths found.

func (w Walker) EverythingTraverse() ([]string, error)

Traverse using Everything index (much faster, Windows only).

Returns a list of paths found.

Notes

  • Exclusions apply to names (not full paths), and always exclude hidden directories (starting with a dot) and AppData by default.
  • If using EverythingTraverse, ensure the following requirements are met:
    • Everything is installed and running.
    • Everything SDK is downloaded and extracted.
    • The file Everything64.dll from the SDK must be placed in the same directory as walk.go or in the same directory as the compiled executable file.
    • The Go package github.com/AWtnb/go-everything is available.

License

MIT

Author

AWtnb

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Walker added in v1.2.0

type Walker struct {
	// contains filtered or unexported fields
}

func (Walker) EverythingTraverse added in v1.2.0

func (w Walker) EverythingTraverse() (found []string, err error)

func (*Walker) Init added in v1.2.0

func (w *Walker) Init(root string, all bool, depth int, exclude string)

`exclude` is comma-separated string

func (Walker) Traverse added in v1.2.0

func (w Walker) Traverse() (found []string, err error)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL