https://github.com/opencoff/go-walk
Concurrent directory tree walker
https://github.com/opencoff/go-walk
concurrency dirwalk filesystem-library filesystem-walk golang golang-dirwalk golang-library
Last synced: about 1 year ago
JSON representation
Concurrent directory tree walker
- Host: GitHub
- URL: https://github.com/opencoff/go-walk
- Owner: opencoff
- License: gpl-2.0
- Created: 2020-05-29T23:36:23.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2024-09-30T01:12:09.000Z (almost 2 years ago)
- Last Synced: 2025-03-31T20:39:11.261Z (over 1 year ago)
- Topics: concurrency, dirwalk, filesystem-library, filesystem-walk, golang, golang-dirwalk, golang-library
- Language: Go
- Homepage:
- Size: 74.2 KB
- Stars: 4
- Watchers: 1
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[](https://godoc.org/github.com/opencoff/go-walk)
# What is this
This is a concurrent directory traversal library. It returns each entry via
a channel or via a caller supplied function (ie callback). In either case,
the caller can specify what entries are interesting:
* Files
* Directories
* Special files (symlinks, device nodes etc.)
* All of the above
It can optionally follow symlinks and detect mount-point crossings.
# How can I use it?
Here is an example program:
```go
dirs := []string{"/etc", "/usr", "/bin", "/sbin", "/lib"}
opt := walk.Options{
OneFS: true,
Type: walk.FILE,
FollowSymlinks: true,
}
ch, errch := walk.Walk(dirs, &opt)
go func() {
for err := range errch {
fmt.Printf("walk: error: %s\n", err)
}
}()
// harvest results
for r := range ch {
fmt.Printf("%s: %d bytes\n", r.Path, r.Stat.Size())
}
```
Here is an example using the `WalkFunc()` API:
```go
dirs := []string{"/etc", "/usr", "/bin", "/sbin", "/lib"}
opt := walk.Options{
OneFS: true,
Type: walk.FILE,
FollowSymlinks: true,
}
err := walk.WalkFunc(dirs, &opt, func(r walk.Result) error {
fmt.Printf("%s: %d bytes\n", r.Path, r.Stat.Size())
})
if err != nil {
fmt.Printf("errors: %s\n", err)
}
```
# Who's using this?
[go-progs](https://github.com/opencoff/go-progs) is a collection of go tools
- many of which use this library.
## Licensing Terms
The tool and code is licensed under the terms of the
GNU Public License v2.0 (strictly v2.0). If you need a commercial
license or a different license, please get in touch with me.
See the file ``LICENSE`` for the full terms of the license.