Skip to content

Instantly share code, notes, and snippets.

@et4891
Last active August 29, 2015 14:08
Show Gist options
  • Save et4891/ab1e17fbaba7f2f10c28 to your computer and use it in GitHub Desktop.
Save et4891/ab1e17fbaba7f2f10c28 to your computer and use it in GitHub Desktop.
Rename File Extention Only in Same Directory
<?php
// open the current directory (change this to modify where you're looking)
$dir = opendir('.');
// loop through all the files in the directory
while (false !== ($file = readdir($dir)))
{
// if the extension is '.jpg'
if (strtolower(pathinfo($file, PATHINFO_EXTENSION)) == 'html')
{
// explode the filename so we can change the extension only and filename stays
$fileName = explode(".", $file);
// gets the first part of the filename after explode and change the extension
$newName = $fileName[0] . '.blade.php';
// do the rename based on the current iteration
rename($file, $newName);
}
}
// close the directory handle
closedir($dir);
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment