Created
September 1, 2016 11:15
-
-
Save wuman/2ae2d188a200148b7e022c2df5e963e6 to your computer and use it in GitHub Desktop.
This file contains 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" | |
"io/ioutil" | |
"log" | |
"os" | |
"regexp" | |
) | |
func main() { | |
files, err := ioutil.ReadDir(".") | |
if err != nil { | |
log.Fatalf("Could not read current directory: %v", err) | |
} | |
validName := regexp.MustCompile(`^((19|20)\d\d)-(0[1-9]|1[012])-(0[1-9]|[12]\d|3[01])_([01]\d|2[0-3])-([0-5]\d)-([0-5]\d).(jpg|jpeg)`) | |
for _, f := range files { | |
if !validName.MatchString(f.Name()) { | |
continue | |
} | |
parts := validName.FindStringSubmatch(f.Name()) | |
y, month, d, h, minute, s, ext := parts[1], parts[3], parts[4], parts[5], parts[6], parts[7], parts[8] | |
name := fmt.Sprintf("%s-%s-%s %s.%s.%s.%s", y, month, d, h, minute, s, ext) | |
err := os.Rename(f.Name(), name) | |
fmt.Printf("%s => %s %v\n", f.Name(), name, err == nil) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment