Golang : Get file permission
Get a file permission in Go is easy. In this tutorial, we will see how to read a file permission and display the permission. This example will use the http://golang.org/pkg/os/#File.Stat function.
getfilepermission.go
package main
import (
"fmt"
"os"
)
func main() {
file := "file.txt"
info,_ := os.Stat(file)
mode := info.Mode()
fmt.Println(file, "mode is " , mode)
}
Test this code out and see the output of file permission.
You should see something similar to this example output :
> go run getfilepermission.go
file.txt mode is -rw-rw-r--
By Adam Ng
IF you gain some knowledge or the information here solved your programming problem. Please consider donating to the less fortunate or some charities that you like. Apart from donation, planting trees, volunteering or reducing your carbon footprint will be great too.
Advertisement
Tutorials
+10.3k Golang : Fuzzy string search or approximate string matching example
+20.1k Golang : Convert(cast) string to rune and back to string example
+8.2k Golang : Temperatures conversion example
+6.3k Golang : File system scanning
+12.8k Golang : How to check if your program is running in a terminal
+5.9k Golang : Takes a plural word and makes it singular
+4.5k Clean up Visual Studio For Mac installation failed disk full problem
+19k Golang : Secure(TLS) connection between server and client
+14.9k Golang : Find out mime type from bytes in buffer
+8.2k Golang : Scramble and unscramble text message by randomly replacing words
+17.3k Golang : Padding data for encryption and un-padding data for decryption
+8.7k Golang : Sort and reverse sort a slice of floats