Created
January 25, 2017 19:10
-
-
Save Noy/4a7d9c7d905078ab10ae2bdebe72022d to your computer and use it in GitHub Desktop.
Had a ton of files that were actually photos but didn't have the extension, this'll fix that if you ever have that problem.
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 ( | |
"io/ioutil" | |
"log" | |
"os" | |
"math/rand" | |
"time" | |
) | |
var randLetters = []rune("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ") | |
func main() { | |
files, err := ioutil.ReadDir(".") | |
if err != nil { log.Fatal(err)} | |
for _, file := range files { | |
if file.Name() == ".idea" { | |
continue | |
} | |
if file.Name() == "main" { | |
continue | |
} | |
os.Rename(file.Name(), randStringRunes(3) +".jpg") | |
} | |
} | |
func init() { | |
rand.Seed(time.Now().UnixNano()) | |
} | |
func randStringRunes(n int) string { | |
b := make([]rune, n) | |
for i := range b { | |
b[i] = randLetters[rand.Intn(len(randLetters))] | |
} | |
return string(b) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment