Walking the Hyperskill file tree

Report a typo

Lena is a very curious programmer. She wants to see what files and directories are behind the Hyperskill Code Editor!

Please help Lena write the required code to use the filepath.Walk() function to walk the root directory "." and output the path/name of every file and directory, following this format:

Directory: .
Directory: .bashrc
File: main.go
File: index.html
...

Remember that it is not necessary to output the file size in this task: you only need to print the file and the directory path or the file name!

Write a program in Go
package main

import (
"fmt"
"log"
"os"
"path/filepath"
)

func main() {
err := ?.?("?", func(path string, info os.FileInfo, err error) error {
if err != nil {
log.Fatal(err)
}
// Check if the walked file is a directory or not below
// Then print the 'path' or file name following the example format above!
if ?.?() {
fmt.Println("Directory:", ?)
} else {
fmt.Println("File:", ?)
}
return nil
})
if err != nil {
log.Fatal(err)
}
}
___

Create a free account to access the full topic