PHP listing files in a directory and renaming them

I have a tons of files in a directory that has underscore in their names, and I need to rename them by replacing underscore to dash.

I wrote this script in PHP and it worked!

$dir = getcwd();
$files = scandir($dir);
foreach ($files as $key => $value){
	if (!in_array($value, array(".",".."))){
		echo "Renaming " . $value . "<br>";
		rename($value, str_replace("JPG", "jpg", $value));

Leave a Reply

Your email address will not be published. Required fields are marked *