Walks through files and fmt.Println

This commit is contained in:
Fred 2020-10-06 20:55:27 +02:00
parent 510c4ef49f
commit 27c59399b5
1 changed files with 17 additions and 15 deletions

32
main.go
View File

@ -8,25 +8,23 @@ import (
"path/filepath"
)
func walk(rootDir string) {
err := filepath.Walk(rootDir,
func(path string, info os.FileInfo, err error) error {
if err != nil {
return err
}
func walk(rootDir string) ([]string, error) {
var files []string
dir, file := filepath.Split(path)
ext := filepath.Ext(file)
err := filepath.Walk(rootDir, func(path string, info os.FileInfo, err error) error {
_, file := filepath.Split(path)
ext := filepath.Ext(file)
if !info.IsDir() && ext == ".md" {
files = append(files, path)
}
return nil
})
if ext == ".md" {
fmt.Println(dir, file, ext, info.Size())
}
return nil
})
if err != nil {
log.Println(err)
}
return files, err
}
func main() {
@ -40,5 +38,9 @@ func main() {
}
flag.Parse()
walk(rootDir)
files, _ := walk(rootDir)
for _, file := range files {
fmt.Println(file)
}
}