Skip to content

Instantly share code, notes, and snippets.

@tetsuok
Created June 6, 2012 04:19
Show Gist options
  • Select an option

  • Save tetsuok/2879902 to your computer and use it in GitHub Desktop.

Select an option

Save tetsuok/2879902 to your computer and use it in GitHub Desktop.
ls utility in Go.
// 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