Created
June 6, 2012 04:19
-
-
Save tetsuok/2879902 to your computer and use it in GitHub Desktop.
ls utility in Go.
This file contains hidden or 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
| // simulates "ls -l" | |
| package main | |
| import ( | |
| "flag" | |
| "fmt" | |
| "io/ioutil" | |
| "log" | |
| ) | |
| func ls(path string) { | |
| entries, err := ioutil.ReadDir(path) | |
| if err != nil { | |
| log.Fatal(err) | |
| } | |
| for _, f := range entries { | |
| fmt.Printf("%v\t%d\t%v\t%s\n", f.Mode(), f.Size(), f.ModTime(), f.Name()) | |
| } | |
| } | |
| func main() { | |
| flag.Parse() | |
| if flag.NArg() >= 1 { | |
| path := flag.Arg(0) | |
| ls(path) | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment