Skip to content

Instantly share code, notes, and snippets.

@YuriyNasretdinov
Created April 11, 2016 15:48
Show Gist options
  • Save YuriyNasretdinov/623de87bef169d823906d65e52b26826 to your computer and use it in GitHub Desktop.
Save YuriyNasretdinov/623de87bef169d823906d65e52b26826 to your computer and use it in GitHub Desktop.
package main
import (
"os"
"flag"
"log"
"io"
"bufio"
)
var bufout = bufio.NewWriter(os.Stdout)
func readdir(dir string) {
dh, err := os.Open(dir)
if err != nil {
log.Fatalf("Could not open %s: %s", dir, err.Error())
}
defer dh.Close()
for {
fis, err := dh.Readdir(10)
if err == io.EOF {
break
}
if err != nil {
log.Fatalf("Could not read dir names in %s: %s", dir, err.Error())
}
for _, fi := range fis {
bufout.WriteString(dir)
bufout.WriteByte('/')
bufout.WriteString(fi.Name())
bufout.WriteByte('\n')
if fi.IsDir() {
readdir(dir + "/" + fi.Name())
}
}
}
}
func main() {
flag.Parse()
if flag.NArg() != 1 {
log.Fatalf("Usage: %s <dir>", os.Args[0])
}
dir := flag.Arg(0)
readdir(dir)
bufout.Flush()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment