began implementing dir traversal
This commit is contained in:
parent
3c8dd525f4
commit
3e6e481c0b
2 changed files with 33 additions and 5 deletions
|
@ -3,6 +3,8 @@ package util
|
|||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"io/fs"
|
||||
"os"
|
||||
"path/filepath"
|
||||
)
|
||||
|
@ -29,3 +31,26 @@ func PathIsValid(path string, requireFile bool) bool {
|
|||
}
|
||||
return err == nil
|
||||
}
|
||||
|
||||
func processFile(path string, entry fs.DirEntry, err error) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if !entry.IsDir() {
|
||||
ext := filepath.Ext(path)
|
||||
switch ext {
|
||||
case ".md":
|
||||
fmt.Println("Processing markdown...")
|
||||
default:
|
||||
// All other file types, we copy!
|
||||
}
|
||||
}
|
||||
fmt.Printf("Visited: %s\n", path)
|
||||
return nil
|
||||
}
|
||||
|
||||
func Traverse(root string) error {
|
||||
// err := filepath.WalkDir(root, func(path string, entry fs.DirEntry, err error) error {
|
||||
err := filepath.WalkDir(root, processFile)
|
||||
return err
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue