1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
package internal import ( "os" ) func CountFiles(dir string) (int, error) { files, err := os.ReadDir(dir) if err != nil { return 0, err } count := 0 for _, file := range files { if !file.IsDir() { count++ } } return count, nil }