Created
May 5, 2017 14:48
-
-
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.
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 ( | |
"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