Sometimes you might need to edit all filenames of directory with a prefix or suffix. Manually changing file name takes long long time and it’s really painful for any programmer. Instead here is a simple code to rename your files (Whatever it is hundred or thousand).
In this example i have shown you all files renamed by postfix _amin (before extension dot). Change it whatever you need. i.e build $NewName as you need.
function Renames($dir)
{
if(!$dh = @opendir($dir)) return;
while (false !== ($obj = readdir($dh))) {
if($obj==’.’ || $obj==’..’) continue;
$NewName=substr($obj,0,strpos($obj,”.”)) . “_amin”.substr($obj,strpos($obj,”.”)); //Useful for Image file
rename($dir.”/”.$obj,$dir.”/”.$NewName);
}
closedir($dh);
}
Renames(“source_dir”);
?>



