Skip to content

Instantly share code, notes, and snippets.

@et4891
Created October 30, 2014 21:39
Show Gist options
  • Save et4891/1f35e29d68af1c422f69 to your computer and use it in GitHub Desktop.
Save et4891/1f35e29d68af1c422f69 to your computer and use it in GitHub Desktop.
Rename File Extention Only in Root All Sub Directories
<?php
// root path
$path = realpath('.');
// finds everything in $path including root directory
$objects = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path), RecursiveIteratorIterator::SELF_FIRST);
// each objects as $file if echo $file files will be printed
foreach($objects as $file => $object){
// if the extension is '.jpg'
if (strtolower(pathinfo($file, PATHINFO_EXTENSION)) == 'php')
{
// do the rename based on the current iteration
$fileName = explode(".", $file);
$newName = $fileName[0] . '.html';
rename($file, $newName);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment