Created
April 11, 2016 15:48
-
-
Save YuriyNasretdinov/623de87bef169d823906d65e52b26826 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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