2017-01-14 01:05:42 +01:00
|
|
|
// Copyright 2016 The Go Authors. All rights reserved.
|
2010-12-03 05:34:57 +01:00
|
|
|
// Use of this source code is governed by a BSD-style
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
|
|
|
package os
|
|
|
|
|
2017-01-14 01:05:42 +01:00
|
|
|
// Readdir reads the contents of the directory associated with file and
|
|
|
|
// returns a slice of up to n FileInfo values, as would be returned
|
|
|
|
// by Lstat, in directory order. Subsequent calls on the same file will yield
|
|
|
|
// further FileInfos.
|
|
|
|
//
|
|
|
|
// If n > 0, Readdir returns at most n FileInfo structures. In this case, if
|
|
|
|
// Readdir returns an empty slice, it will return a non-nil error
|
|
|
|
// explaining why. At the end of a directory, the error is io.EOF.
|
|
|
|
//
|
|
|
|
// If n <= 0, Readdir returns all the FileInfo from the directory in
|
|
|
|
// a single slice. In this case, if Readdir succeeds (reads all
|
|
|
|
// the way to the end of the directory), it returns the slice and a
|
|
|
|
// nil error. If it encounters an error before the end of the
|
|
|
|
// directory, Readdir returns the FileInfo read until that point
|
|
|
|
// and a non-nil error.
|
|
|
|
func (f *File) Readdir(n int) ([]FileInfo, error) {
|
|
|
|
if f == nil {
|
|
|
|
return nil, ErrInvalid
|
2010-12-03 05:34:57 +01:00
|
|
|
}
|
2017-01-14 01:05:42 +01:00
|
|
|
return f.readdir(n)
|
2010-12-03 05:34:57 +01:00
|
|
|
}
|
|
|
|
|
2017-01-14 01:05:42 +01:00
|
|
|
// Readdirnames reads and returns a slice of names from the directory f.
|
|
|
|
//
|
|
|
|
// If n > 0, Readdirnames returns at most n names. In this case, if
|
|
|
|
// Readdirnames returns an empty slice, it will return a non-nil error
|
|
|
|
// explaining why. At the end of a directory, the error is io.EOF.
|
|
|
|
//
|
|
|
|
// If n <= 0, Readdirnames returns all the names from the directory in
|
|
|
|
// a single slice. In this case, if Readdirnames succeeds (reads all
|
|
|
|
// the way to the end of the directory), it returns the slice and a
|
|
|
|
// nil error. If it encounters an error before the end of the
|
|
|
|
// directory, Readdirnames returns the names read until that point and
|
|
|
|
// a non-nil error.
|
|
|
|
func (f *File) Readdirnames(n int) (names []string, err error) {
|
|
|
|
if f == nil {
|
|
|
|
return nil, ErrInvalid
|
2010-12-03 05:34:57 +01:00
|
|
|
}
|
2017-01-14 01:05:42 +01:00
|
|
|
return f.readdirnames(n)
|
2010-12-03 05:34:57 +01:00
|
|
|
}
|