Skip to content

Instantly share code, notes, and snippets.

@Ramko9999

Ramko9999/walkDir.go

Created Apr 25, 2021
Embed
What would you like to do?
import (
"fmt"
"io/fs"
"path/filepath"
)
// example of counting all files in a root directory
func countFiles() int {
count := 0;
filepath.WalkDir(".", func(path string, file fs.DirEntry, err error) error {
if err != nil {
return err
}
if !file.IsDir() {
fmt.Println(path);
count++;
}
return nil;
});
return count;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment