neko/internal/plugins/filetransfer/utils.go
2024-04-19 20:22:43 +02:00

33 lines
523 B
Go

package filetransfer
import "os"
func ListFiles(path string) ([]Item, error) {
items, err := os.ReadDir(path)
if err != nil {
return nil, err
}
out := make([]Item, len(items))
for i, item := range items {
var itemType ItemType
var size int64 = 0
if item.IsDir() {
itemType = ItemTypeDir
} else {
itemType = ItemTypeFile
info, err := item.Info()
if err == nil {
size = info.Size()
}
}
out[i] = Item{
Name: item.Name(),
Type: itemType,
Size: size,
}
}
return out, nil
}