Advertisement
DRVTiny

showDir

Sep 24th, 2021
1,197
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Go 0.46 KB | None | 0 0
  1. package main
  2.  
  3. import (
  4.         "fmt"
  5.         "log"
  6.         "os"
  7. )
  8.  
  9. func showDir (path string, pfx string) {
  10.     files, err := os.ReadDir(path)
  11.     if err != nil {
  12.             log.Fatal(err)
  13.     }
  14.  
  15.     for _, fileOrDir := range files {
  16.         fdName := fileOrDir.Name()
  17.         fmt.Println(pfx + fdName)
  18.         if fileOrDir.IsDir() {
  19.             showDir(path + "/" + fdName, pfx + "\t")
  20.         }
  21.  
  22.     }
  23. }
  24.  
  25. func main() {
  26.         showDir(".", "")
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement