MCPcopy Create free account
hub / github.com/NVIDIA/gpu-operator / GetFilesWithSuffix

Function GetFilesWithSuffix

internal/utils/utils.go:35–61  ·  view source on GitHub ↗

GetFilesWithSuffix returns all files under a given base directory that have a specific suffix The operation is performed recursively on subdirectories as well

(baseDir string, suffixes ...string)

Source from the content-addressed store, hash-verified

33// GetFilesWithSuffix returns all files under a given base directory that have a specific suffix
34// The operation is performed recursively on subdirectories as well
35func GetFilesWithSuffix(baseDir string, suffixes ...string) ([]string, error) {
36 var files []string
37 err := filepath.Walk(baseDir, func(path string, info os.FileInfo, err error) error {
38 // Error during traversal
39 if err != nil {
40 return err
41 }
42
43 if info.IsDir() {
44 return nil
45 }
46
47 // Skip non suffix files
48 base := info.Name()
49 for _, s := range suffixes {
50 if strings.HasSuffix(base, s) {
51 files = append(files, path)
52 }
53 }
54 return nil
55 })
56
57 if err != nil {
58 return nil, fmt.Errorf("error traversing directory tree: %w", err)
59 }
60 return files, nil
61}
62
63var spewPrinter = spew.ConfigState{
64 Indent: " ",

Callers 2

NewStateDriverFunction · 0.92
getFilesFromDirFunction · 0.92

Calls 1

NameMethod · 0.65

Tested by 1

getFilesFromDirFunction · 0.74