Created
March 7, 2014 12:40
-
-
Save mortdeus/9410743 to your computer and use it in GitHub Desktop.
code that walks a file system directory hierarchy renaming a bunch of ugly ogg files I pulled from a server with wget.
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 ( | |
"fmt" | |
"os" | |
"path/filepath" | |
) | |
func main() { | |
err := filepath.Walk(os.Getenv("PWD"), walk) | |
if err != err && err != filepath.SkipDir { | |
panic(err) | |
} | |
} | |
func walk(path string, info os.FileInfo, err error) error { | |
fmt.Printf("%v,\t%v,\t%v\n", path, info.Name(), err) | |
if err != nil { | |
fmt.Printf("%v,\t%v,\t%v\n", path, info.Name(), err) | |
return filepath.SkipDir | |
} | |
if info.IsDir() { | |
fmt.Println(os.Getenv("PWD")) | |
fmt.Println(path) | |
return os.Chdir(path) | |
} | |
if len(info.Name()) > 6 && filepath.Ext(info.Name()) == ".ogg" { | |
fmt.Printf("%v -> %v\n", info.Name(), info.Name()[:2]+".ogg") | |
err := os.Rename(info.Name(), info.Name()[:2]+".ogg") | |
if err != nil { | |
fmt.Println(err) | |
return err | |
} | |
return nil | |
} | |
return os.Chdir("..") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment