...
Run Format

Source file src/os/dir.go

Documentation: os

     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 and returns a slice of names from the directory f.
    30  //
    31  // If n > 0, Readdirnames returns at most n names. In this case, if
    32  // Readdirnames returns an empty slice, it will return a non-nil error
    33  // explaining why. At the end of a directory, the error is io.EOF.
    34  //
    35  // If n <= 0, Readdirnames returns all the names from the directory in
    36  // a single slice. In this case, if Readdirnames succeeds (reads all
    37  // the way to the end of the directory), it returns the slice and a
    38  // nil error. If it encounters an error before the end of the
    39  // directory, Readdirnames returns the names read until that point and
    40  // a non-nil error.
    41  func (f *File) Readdirnames(n int) (names []string, err error) {
    42  	if f == nil {
    43  		return nil, ErrInvalid
    44  	}
    45  	return f.readdirnames(n)
    46  }
    47  

View as plain text