Skip to content

Instantly share code, notes, and snippets.

@vjandrea
Last active September 7, 2018 17:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vjandrea/6ad9e0f4d0e6bd8c625939c031c4ffd3 to your computer and use it in GitHub Desktop.
Save vjandrea/6ad9e0f4d0e6bd8c625939c031c4ffd3 to your computer and use it in GitHub Desktop.
Generate .iconset folders from a bunch of .png files
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