first commit
This commit is contained in:
34
scanner.go
Normal file
34
scanner.go
Normal file
@@ -0,0 +1,34 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func findFiles(config Config) ([]string, error) {
|
||||
var musicFiles []string
|
||||
|
||||
walkFunc := func(path string, info os.FileInfo, err error) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if info.IsDir() && path != config.SourceDir && !config.Recursion {
|
||||
return filepath.SkipDir
|
||||
}
|
||||
|
||||
ext := strings.ToLower(filepath.Ext(path))
|
||||
if ext == ".mp3" || ext == ".m4a" || ext == ".flac" || ext == ".wav" {
|
||||
musicFiles = append(musicFiles, path)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
if err := filepath.Walk(config.SourceDir, walkFunc); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return musicFiles, nil
|
||||
}
|
||||
Reference in New Issue
Block a user