Skip to content

Instantly share code, notes, and snippets.

@rock3r
Last active April 28, 2017 23:43
Show Gist options
  • Star 21 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rock3r/199a7741bd6a0ffb93e7 to your computer and use it in GitHub Desktop.
Save rock3r/199a7741bd6a0ffb93e7 to your computer and use it in GitHub Desktop.
Move/rename *-{m|h|xh|xxh|xxxh}dpi.png" assets into proper folder structure, ready for copypasta
#!/bin/bash
# License for any modification to the original (linked below):
# ----------------------------------------------------------------------------
# "THE BEER-WARE LICENSE" (Revision 42):
# Sebastiano Poggi wrote this file. As long as you retain this notice you
# can do whatever you want with this stuff. If we meet some day, and you think
# this stuff is worth it, you can buy me a beer in return.
# ----------------------------------------------------------------------------
prefix=${1-"drawable"}
buckets=( mdpi hdpi xhdpi xxhdpi xxxhdpi )
for density in "${buckets[@]}"
do
mkdir -p "$prefix-${density}"
for f in *-"$density.png"
do
newName=${f/-$density.png/.png}
mv -i "$f" "$prefix-$density/$newName"
done
done
@rock3r
Copy link
Author

rock3r commented Jan 8, 2015

This gist is a bash script that takes in all the files in the current directory that match this regex:
(.*)-((:?m|h|xh|xxh|xxxh)dpi)\.png$
and renames/moves them to:
drawable-$2/$1.png

E.g.: the file ic_test_icon-hdpi.png is moved/renamed to drawable-hdpi/ic_test_icon.png

@rock3r
Copy link
Author

rock3r commented Jan 8, 2015

As a side note, if your file names don't have dashes but underscores to separate the density bucket from the rest of the file name (e.g. my_image_hdpi.png instead of my_image-hdpi.png), just edit line 6 and swap out the - replacing it with whatever you might need.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment