Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace filepath.Walk with filepath.WalkDir #605

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions folder/folderutil.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package folderutil

import (
"io/fs"
"os"
"path/filepath"
"runtime"
Expand Down Expand Up @@ -30,11 +31,11 @@ const (
// GetFiles within a folder
func GetFiles(root string) ([]string, error) {
var matches []string
err := filepath.Walk(root, func(path string, info os.FileInfo, err error) error {
err := filepath.WalkDir(root, func(path string, d fs.DirEntry, err error) error {
if err != nil {
return err
}
if info.IsDir() {
if d.IsDir() {
return nil
}
matches = append(matches, path)
Expand Down Expand Up @@ -241,11 +242,11 @@ func SyncDirectory(source, destination string) error {
// DedupeLinesInFiles deduplicates lines in all files in a directory
// The function can be memory intensive for directories with large files.
func DedupeLinesInFiles(dir string) error {
err := filepath.Walk(dir, func(path string, info os.FileInfo, err error) error {
err := filepath.WalkDir(dir, func(path string, d fs.DirEntry, err error) error {
if err != nil {
return err
}
if !info.IsDir() {
if !d.IsDir() {
return fileutil.DedupeLines(path)
}
return nil
Expand Down
6 changes: 3 additions & 3 deletions memoize/gen/generic/memoize.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@ var (
func main() {
flag.Parse()

err := filepath.Walk(*src, walk)
err := filepath.WalkDir(*src, walkDir)
if err != nil {
log.Fatal(err)
}
}

func walk(path string, info fs.FileInfo, err error) error {
if info.IsDir() {
func walkDir(path string, d fs.DirEntry, err error) error {
if d.IsDir() {
return nil
}

Expand Down
Loading