Skip to content

Instantly share code, notes, and snippets.

@et4891
Created October 30, 2014 06:17
Show Gist options
  • Save et4891/e9565b45226a6e196163 to your computer and use it in GitHub Desktop.
Save et4891/e9565b45226a6e196163 to your computer and use it in GitHub Desktop.
rename all files in a directory with same extentions
<?php
// open the current directory (change this to modify where you're looking)
$dir = opendir('.');
$i = 1;
// loop through all the files in the directory
while (false !== ($file = readdir($dir)))
{
// if the extension is '.jpg'
if (strtolower(pathinfo($file, PATHINFO_EXTENSION)) == 'jpg')
{
// do the rename based on the current iteration
$newName = 'melody_galleries' . $i . '.jpg';
rename($file, $newName);
// increase for the next loop
$i++;
}
}
// close the directory handle
closedir($dir);
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment