github.com/blend/go-sdk@v1.20220411.3/sourceutil/ls.go (about) 1 /* 2 3 Copyright (c) 2022 - Present. Blend Labs, Inc. All rights reserved 4 Use of this source code is governed by a MIT license that can be found in the LICENSE file. 5 6 */ 7 8 package sourceutil 9 10 import ( 11 "os" 12 "path/filepath" 13 ) 14 15 // FileInfo extends os.FileInfo with the full path. 16 type FileInfo struct { 17 os.FileInfo 18 FullPath string 19 } 20 21 // LS returns a list of files for a given path. 22 func LS(root string) (output []FileInfo, err error) { 23 err = filepath.Walk(root, func(path string, info os.FileInfo, err error) error { 24 if path == root { 25 return nil 26 } 27 output = append(output, FileInfo{ 28 FileInfo: info, 29 FullPath: path, 30 }) 31 if info.IsDir() { 32 return filepath.SkipDir 33 } 34 return nil 35 }) 36 return 37 }