O'Reilly logo

Go Standard Library Cookbook by Radomir Sohlich

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

How it works...

The folder listing the example above uses two approaches. The first, simpler one is implemented by using the listDirByReadDir function and utilizes the ReadDir function from the ioutil package. This function returns the slice of FileInfo structs that represent the actual directory content. Note that the ReadDir function does not read the folders recursively. In fact, the ReadDir function internally uses the Readdir method of the File type in the os package.

On the other hand, the more complicated listDirByWalk uses the filepath.Walk function which consumes the path to be walked and has a function that processes each file or folder in any given path. The main difference is that the Walk function reads the directory recursively. ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required