Added utility method to DirEntries for reading all entries.
This commit is contained in:
parent
92af9f1b15
commit
bdf8f854c3
|
@ -24,6 +24,20 @@ type DirEntries struct {
|
||||||
err error
|
err error
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ReadAllDirEntries reads all the remaining directory entries into a slice,
|
||||||
|
// closes self, and returns any error.
|
||||||
|
// If err is non-nil, result will contain any entries read until the error occurred.
|
||||||
|
func (entries *DirEntries) ReadAll() (result []*DirEntry, err error) {
|
||||||
|
defer entries.Close()
|
||||||
|
|
||||||
|
for entries.Next() {
|
||||||
|
result = append(result, entries.Entry())
|
||||||
|
}
|
||||||
|
err = entries.Err()
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
func (entries *DirEntries) Next() bool {
|
func (entries *DirEntries) Next() bool {
|
||||||
if entries.err != nil {
|
if entries.err != nil {
|
||||||
return false
|
return false
|
||||||
|
|
Loading…
Reference in a new issue