Skip to content

Instantly share code, notes, and snippets.

@AmyStephen
Last active December 24, 2015 15:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save AmyStephen/6817915 to your computer and use it in GitHub Desktop.
Save AmyStephen/6817915 to your computer and use it in GitHub Desktop.
Quick and dirty rename of all files of one file extension to another (in this case, .html.php to .phtml)
<?php
$objects = new RecursiveIteratorIterator
(new RecursiveDirectoryIterator(__DIR__),
RecursiveIteratorIterator::SELF_FIRST);
foreach ($objects as $path => $fileObject) {
$use = true;
$file_name = '';
$base_name = '';
if (is_dir($fileObject)) {
if ($fileObject->getFileName() == '.' || $fileObject->getFileName() == '..') {
} else {
$path = $fileObject->getPathName();
foreach (scandir($path) as $filename) {
if ($filename == '.' || $filename == '..') {
} else {
$newname = preg_replace('"\.html.php"', '.phtml', $filename);
rename($path . '/' . $filename, $path . '/' . $newname);
}
}
}
}
}
@AmyStephen
Copy link
Author

Thanks again, @peterjmit

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment