mirror of
https://github.com/golang/go
synced 2024-10-06 08:00:07 +00:00
os: show how to print permission bits in octal
Permission bits are most commonly viewed in string form (rwx-- etc) or in octal form (0755), but the latter is relatively rare in Go. Demonstrate how to print a FileMode in readable octal format. Change-Id: I41feb801bcecb5077d4eabafdea27c149fc179a1 Reviewed-on: https://go-review.googlesource.com/c/154423 Run-TryBot: Ian Lance Taylor <iant@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
This commit is contained in:
parent
7ef718f16f
commit
c343b6b2b8
|
@ -55,6 +55,7 @@ func ExampleFileMode() {
|
|||
log.Fatal(err)
|
||||
}
|
||||
|
||||
fmt.Printf("permissions: %#o\n", fi.Mode().Perm()) // 0400, 0777, etc.
|
||||
switch mode := fi.Mode(); {
|
||||
case mode.IsRegular():
|
||||
fmt.Println("regular file")
|
||||
|
|
Loading…
Reference in a new issue