This recipe describes a few general ways you can create files and directories in code.
Creating files and directories
How to do it...
- Open the console and create the folder chapter06/recipe07.
- Navigate to the directory.
- 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("...