Last active
September 7, 2018 17:11
-
-
Save vjandrea/6ad9e0f4d0e6bd8c625939c031c4ffd3 to your computer and use it in GitHub Desktop.
Generate .iconset folders from a bunch of .png files
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
import os, re, sys | |
# setup | |
path = './' | |
separator = '-' # this implies a filename as "iconname_somewords-16x16.png" | |
# runtime | |
current_folder = "" | |
files = sorted(os.listdir(path)) | |
for file in files: | |
# skip dotfiles | |
if re.match(r'\.', file): | |
continue | |
if re.search(r'png', file) and re.search(separator, file): | |
pcs = re.split('[-]', file) | |
if current_folder == "" or current_folder != pcs[0]: | |
current_folder = pcs[0] | |
# TODO: check if folder already exists before mkdir | |
os.mkdir(path + current_folder + '.iconset') | |
if re.search(current_folder, file): | |
os.rename(path + file, path + current_folder + '.iconset/' + 'icon_' + pcs[1]) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment