MCPcopy Create free account
hub / github.com/codeyourweb/irma / RetrivesFilesFromUserPath

Function RetrivesFilesFromUserPath

filehelper.go:158–199  ·  view source on GitHub ↗

RetrivesFilesFromUserPath return a []string of available files from given path (includeFileExtensions is available only if listFiles is true)

(path string, listFiles bool, includeFileExtensions []string, recursive bool, verbose bool)

Source from the content-addressed store, hash-verified

156
157// RetrivesFilesFromUserPath return a []string of available files from given path (includeFileExtensions is available only if listFiles is true)
158func RetrivesFilesFromUserPath(path string, listFiles bool, includeFileExtensions []string, recursive bool, verbose bool) ([]string, error) {
159 var p []string
160
161 info, err := os.Stat(path)
162 if os.IsNotExist(err) {
163 return []string{}, errors.New("Input file not found")
164 }
165
166 if !info.IsDir() {
167 p = append(p, path)
168 } else {
169 if !recursive {
170 files, err := os.ReadDir(path)
171 if err != nil {
172 return []string{}, err
173 }
174 for _, f := range files {
175 if !(f.IsDir() == listFiles) && (len(includeFileExtensions) == 0 || StringInSlice(filepath.Ext(f.Name()), includeFileExtensions)) {
176 p = append(p, path+string(os.PathSeparator)+f.Name())
177 }
178 }
179 } else {
180 err := filepath.Walk(path, func(walk string, info os.FileInfo, err error) error {
181 if err != nil && verbose {
182 logMessage(LOG_ERROR, "[ERROR]", err)
183 }
184
185 if err == nil && !(info.IsDir() == listFiles) && (len(includeFileExtensions) == 0 || StringInSlice(filepath.Ext(walk), includeFileExtensions)) {
186 p = append(p, walk)
187 }
188
189 return nil
190 })
191
192 if err != nil && verbose {
193 logMessage(LOG_ERROR, "[ERROR]", err)
194 }
195 }
196 }
197
198 return p, nil
199}

Callers 7

ListStartMenuFoldersFunction · 0.85
ListUserWorkspaceFilesFunction · 0.85
ListEnvironmentPathFilesFunction · 0.85
ListTemporaryFilesFunction · 0.85
SearchForYaraFilesFunction · 0.85
mainFunction · 0.85

Calls 2

StringInSliceFunction · 0.85
logMessageFunction · 0.85

Tested by

no test coverage detected