Skip to content

Instantly share code, notes, and snippets.

@eluleci
Created May 5, 2017 14:48
Show Gist options
  • Save eluleci/fb47e06c865659efc41e4c3dacd8a30a to your computer and use it in GitHub Desktop.
Save eluleci/fb47e06c865659efc41e4c3dacd8a30a to your computer and use it in GitHub Desktop.
Go app that separates the list of android drawables. It expects icons to have ...-xhdpi.png suffix on all items.
package main
import (
"os"
"strings"
"io/ioutil"
)
func main() {
files, _ := ioutil.ReadDir("./")
for _, f := range files {
fileName := f.Name()
if !strings.Contains(fileName, ".") {
continue
}
fileParts := strings.Split(fileName, ".")
if !strings.EqualFold(fileParts[1], "png") {
continue;
}
fileNameParts := strings.Split(fileParts[0], "-")
drawableFolderName := fileNameParts[len(fileNameParts)-1:][0]
if _, err := os.Stat(drawableFolderName); os.IsNotExist(err) {
os.Mkdir("drawable-" + drawableFolderName, os.ModePerm)
}
fileNameWithoutDrawableRes := strings.Replace(fileName, "-" + drawableFolderName, "", -1)
os.Rename(fileName, "drawable-" + drawableFolderName + "/" + fileNameWithoutDrawableRes)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment