1 // Copyright 2016 The Go Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 package os 6 7 // Readdir reads the contents of the directory associated with file and 8 // returns a slice of up to n FileInfo values, as would be returned 9 // by Lstat, in directory order. Subsequent calls on the same file will yield 10 // further FileInfos. 11 // 12 // If n > 0, Readdir returns at most n FileInfo structures. In this case, if 13 // Readdir returns an empty slice, it will return a non-nil error 14 // explaining why. At the end of a directory, the error is io.EOF. 15 // 16 // If n <= 0, Readdir returns all the FileInfo from the directory in 17 // a single slice. In this case, if Readdir succeeds (reads all 18 // the way to the end of the directory), it returns the slice and a 19 // nil error. If it encounters an error before the end of the 20 // directory, Readdir returns the FileInfo read until that point 21 // and a non-nil error. 22 func (f *File) Readdir(n int) ([]FileInfo, error) { 23 if f == nil { 24 return nil, ErrInvalid 25 } 26 return f.readdir(n) 27 } 28 29 // Readdirnames reads the contents of the directory associated with file 30 // and returns a slice of up to n names of files in the directory, 31 // in directory order. Subsequent calls on the same file will yield 32 // further names. 33 // 34 // If n > 0, Readdirnames returns at most n names. In this case, if 35 // Readdirnames returns an empty slice, it will return a non-nil error 36 // explaining why. At the end of a directory, the error is io.EOF. 37 // 38 // If n <= 0, Readdirnames returns all the names from the directory in 39 // a single slice. In this case, if Readdirnames succeeds (reads all 40 // the way to the end of the directory), it returns the slice and a 41 // nil error. If it encounters an error before the end of the 42 // directory, Readdirnames returns the names read until that point and 43 // a non-nil error. 44 func (f *File) Readdirnames(n int) (names []string, err error) { 45 if f == nil { 46 return nil, ErrInvalid 47 } 48 return f.readdirnames(n) 49 } 50