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 to do it...

  1. Open the console and create the folder chapter06/recipe07.
  2. Navigate to the directory.
  3. Create the create.go file with the following content:
        package main        import (          "os"        )        func main() {          f, err := os.Create("created.file")          if err != nil {            panic(err)          }          f.Close()          f, err = os.OpenFile("created.byopen", os.O_CREATE|os.O_APPEND,                               os.ModePerm)          if err != nil {            panic(err)          }          f.Close()          err = os.Mkdir("createdDir", 0777)          if err != nil {            panic(err)          }          err = os.MkdirAll("sampleDir/path1/path2", 0777)          if err != nil {            panic(err)          }        }
  1. Execute the code by running go run create.go in the main Terminal.
  2. List the content of  the chapter06/recipe07 directory:

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