20seven

Devigner blog about development and design

Renaming a Thumb

While working on migrating a shopping cart for a client to a newer cart I found that the product thumbnail naming conventions were different between carts. I also noticed they had just shy of 2500 images to be renamed, so within 5 minutes time they were all prefixed with thumb_. Here’s how I did it and hope someone else finds it useful.

$the_array = Array();
$handle = opendir(‘images/uploads/thumbs/’);

while (false !== ($file = readdir($handle))) {
   if ($file != “.” && $file != “..”) {
      $the_array[] = $file;
   }
}
closedir($handle);

foreach ($the_array as $element) {
   rename(“images/uploads/thumbs/$element”, “images/uploads/thumbs/thumb_”.$element);
}
?>