began implementing dir traversal

This commit is contained in:
Daniel Fichtinger 2024-11-09 01:00:44 -05:00
parent 3c8dd525f4
commit 3e6e481c0b
2 changed files with 33 additions and 5 deletions

View file

@ -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
}