Created
October 30, 2014 21:39
-
-
Save et4891/1f35e29d68af1c422f69 to your computer and use it in GitHub Desktop.
Rename File Extention Only in Root All Sub Directories
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 | |
// 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