Skip to content

Instantly share code, notes, and snippets.

@Noy
Created January 25, 2017 19:10
Show Gist options
  • Save Noy/4a7d9c7d905078ab10ae2bdebe72022d to your computer and use it in GitHub Desktop.
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.
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