photoprism/pkg/fs/dirs.go
Michael Mayer 2d1763edbe Add videos to main navigation #17
Signed-off-by: Michael Mayer <michael@liquidbytes.net>
2020-05-14 19:03:12 +02:00

42 lines
733 B
Go

package fs
import (
"os"
"path/filepath"
"sort"
"strings"
"sync"
"github.com/photoprism/photoprism/pkg/fastwalk"
)
func Dirs(root string, recursive bool) (result []string, err error) {
result = []string{}
ignore := NewIgnoreList(".ppignore", true, false)
mutex := sync.Mutex{}
err = fastwalk.Walk(root, func(fileName string, info os.FileMode) error {
if info.IsDir() {
if ignore.Ignore(fileName) {
return filepath.SkipDir
}
if fileName != root {
mutex.Lock()
fileName = strings.Replace(fileName, root, "", 1)
result = append(result, fileName)
mutex.Unlock()
if !recursive {
return filepath.SkipDir
}
}
}
return nil
})
sort.Strings(result)
return result, err
}