The FileMode type

Report a typo

You need to create a program that takes as an input a file or directory name and then prints its permission bits and whether it is a directory or not.

Remember that you can get these file attributes with the FileMode type! Write the additional code below to first get the FileMode type within the mode variable, and then print the required file attributes!

Sample Input 1:

main.go

Sample Output 1:

File permission bits: 0644
Is directory: false
Write a program in Go
package main

import (
"fmt"
"log"
"os"
)

func main() {
var fileName string
fmt.Scanln(&fileName)

fileInfo, err := os.Stat(fileName)
if err != nil {
log.Fatal(err)
}

mode := ?
fmt.Printf("File permission bits: %#o\n", ?)
fmt.Println("Is directory:", ?)
}
___

Create a free account to access the full topic