This recipe illustrates how file permissions can be changed programmatically.
Changing file permissions
How to do it...
- Open the console and create the folder chapter06/recipe06.
- Navigate to the directory.
- Create the filechmod.go file with the following content:
package main
import (
"fmt"
"os"
)
func main() {
f, err := os.Create("test.file")
if err != nil {
panic(err)
}
defer f.Close()
// Obtain current permissions
fi, err := f.Stat()
if err != nil {
panic(err)
}
fmt.Printf("File permissions %v\n", fi.Mode())
// Change permissions...