DRVTiny

showDir

Sep 24th, 2021
638
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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. }
RAW Paste Data