BREAKING: Rapporter fichiers `pkg/*.go` à la racine BREAKING: Bump version du module à `git.agecem.com/agecem/babillard/v8` et ajuster les références
42 lines
736 B
Go
42 lines
736 B
Go
package babillard
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
)
|
|
|
|
var forbiddenFiles = []string{".gitkeep", "messages.txt", "Thumbs.db"}
|
|
|
|
func ListContenu(path string) (files []string, err error) {
|
|
file, err := os.Open(path)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer file.Close()
|
|
|
|
stats, err := file.Stat()
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
if !stats.IsDir() {
|
|
return nil, fmt.Errorf("contenu '%s' n'est pas un répertoire", path)
|
|
}
|
|
|
|
fileInfos, err := file.Readdir(-1)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
fileLoop:
|
|
for _, fileInfo := range fileInfos {
|
|
for _, forbiddenFile := range forbiddenFiles {
|
|
if fileInfo.Name() == forbiddenFile {
|
|
continue fileLoop
|
|
}
|
|
}
|
|
files = append(files, fileInfo.Name())
|
|
}
|
|
|
|
return files, nil
|
|
}
|