Created
October 30, 2014 06:17
-
-
Save et4891/e9565b45226a6e196163 to your computer and use it in GitHub Desktop.
rename all files in a directory with same extentions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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