Forked from et4891/renameFilesExtension-AllPaths-With-Stats.php
Last active
August 29, 2015 14:08
-
-
Save marcelaraujo/f2ee951065cd6b681a99 to your computer and use it in GitHub Desktop.
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); | |
$success = 0; | |
$error = 0; | |
$skipped = 0; | |
$new_extension = '.blade.php'; | |
$skipped_file = ''; | |
// each objects as $file if echo $file files will be printed | |
foreach($objects as $file => $object){ | |
// extension to search and rename | |
if (strtolower(pathinfo($file, PATHINFO_EXTENSION)) == 'html') | |
{ | |
// explode file to get the filename without extension | |
$fileName = explode(".", $file); | |
// renaming into the extension wanted | |
$newName = $fileName[0] . $new_extension; | |
rename($file, $newName); | |
$success++; | |
} | |
// files to skip | |
elseif (strtolower(pathinfo($file, PATHINFO_EXTENSION)) == 'php') | |
{ | |
$skipped_file .= '<b>Rename Skipped: </b>'.$file.' <br>'; | |
$skipped++; | |
continue; | |
} | |
// rename failed because these are not the extension wanted to change | |
else | |
{ | |
echo '<b>Rename Error: </b>'.$file.' <br>'; | |
$error++; | |
} | |
} | |
echo '<h1 style="color:red;">' . $success . ' Renamed Successfully<br></h1>'; | |
echo '<h2 style="color:blue;">' . $error . ' Failed Renaming</h2>'; | |
echo '<h3 style="color:green;">' . $skipped . ' Skipped</h3><br>'; | |
echo $skipped_file; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment