Created
July 1, 2013 09:47
-
-
Save yannick/5899618 to your computer and use it in GitHub Desktop.
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
| 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