Skip to content

Instantly share code, notes, and snippets.

@yannick
Created July 1, 2013 09:47
Show Gist options
  • Select an option

  • Save yannick/5899618 to your computer and use it in GitHub Desktop.

Select an option

Save yannick/5899618 to your computer and use it in GitHub Desktop.
package main
import (
"flag"
"fmt"
"os"
"path/filepath"
)
type MovieCollector struct {
Root string
Movies map[string][]string
}
func (collector *MovieCollector) Visit(path string, f os.FileInfo, err error) error {
if collector.Root == path {
return nil
}
//add ".ts" files per directory
if len(path) > 3 && path[len(path)-3:] == ".ts" {
dir, file := filepath.Split(path)
collector.Movies[dir] = append(collector.Movies[dir], file)
fmt.Printf("%#v added TS file: %#v \n", dir, file)
}
return nil
}
func main() {
flag.Parse()
root := flag.Arg(0)
movies := MovieCollector{Root: root, Movies: make(map[string][]string)}
err := filepath.Walk(root, movies.Visit)
fmt.Printf("filepath.Walk() returned %v\n", err)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment