Skip to content

Instantly share code, notes, and snippets.

@benigumocom
Last active August 29, 2015 14:08
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 benigumocom/a5624d94343382bc9222 to your computer and use it in GitHub Desktop.
Save benigumocom/a5624d94343382bc9222 to your computer and use it in GitHub Desktop.
ディレクトリ構成を変更
<?php
/**
Restructure dirs/files tree.
https://github.com/google/material-design-icons
Usage:
$ curl -LO https://github.com/google/material-design-icons/archive/master.zip
$ unzip material-design-icons-master.zip
$ ls
... material-design-icons-master ...
$ php restructure.php
{category}/drawable-{dpi}/ic_{name}_{color}_{dip}.png
-> {category}/{name}/{color}/{dip}/drawable-{dpi}/ic_{name}.png
~/material-design-icons-master_new $ tree .
.
├── action
│   ├── 3d_rotation
│   │   ├── black
│   │   │   ├── 18dp
│   │   │   │   ├── drawable-hdpi
│   │   │   │   │   └── ic_3d_rotation.png
│   │   │   │   ├── drawable-mdpi
│   │   │   │   │   └── ic_3d_rotation.png
│   │   │   │   ├── drawable-xhdpi
│   │   │   │   │   └── ic_3d_rotation.png
│   │   │   │   ├── drawable-xxhdpi
│   │   │   │   │   └── ic_3d_rotation.png
│   │   │   │   └── drawable-xxxhdpi
│   │   │   │   └── ic_3d_rotation.png
│   │   │   ├── 24dp
│   │   │   │   ├── drawable-hdpi
│   │   │   │   │   └── ic_3d_rotation.png
│   │   │   │   ├── drawable-mdpi
│   │   │   │   │   └── ic_3d_rotation.png
...
*/
foreach (glob('material-design-icons-master/*/*/*.png') as $file) {
if (is_file($file) && preg_match('@/drawable@', $file)) {
$path_parts = pathinfo($file);
$filename = $path_parts['filename'];
$dirs = explode('/', $path_parts['dirname']);
$category = $dirs[1];
$dip = substr($filename, strrpos($filename, '_') + 1);
$dpi = substr($dirs[2], strpos($dirs[2], '-') + 1);
$filename = substr($filename, 0, strpos($filename, '_' . $dip));
$name_color = substr($filename, strpos($filename, '_') + 1);
$color = substr($name_color, strrpos($name_color, '_') + 1);
$name = substr($name_color, 0, strpos($name_color, '_' . $color));
$path = sprintf('%s_new/%s/%s/%s/%s/drawable-%s/ic_%s.png',
$dirs[0], $category, $name, $color, $dip, $dpi, $name);
mkdir(dirname($path), 0777, true);
copy($file, $path);
echo $file . "\n";
echo '-> ' . $path . "\n";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment