Home > Article > Backend Development > PHP batch rename_PHP tutorial
PHP batch renaming This program is divided into simple single file renaming. By adding getfile, you can realize batch renaming of files. $path is the directory you want to rename. It can put the specified file type in the specified directory after discussion. Batch rename. Very easy to use.
PHP tutorial batch renaming
This program is divided into simple single file renaming, adding getfile can realize batch renaming of files, $path is the key The directory you renamed can rename the comments of the specified file type in the specified directory in batches. Very easy to use.
*/
$format ='php';
$path ='www.bkjia.com/';
$files = getfile($path,$format) ;foreach( $files as $v )
{
$tv = basename($v);
list($name,$ext) = explode('.',$ tv);
$newname =$path.time().mt_rand(1,10000).'.'.$ext;
if(rename($v,$newname))
{
echo 'Successfully renamed '.$v.' to '.$newname.'
';
}
}function getfile($path,$format)
{
$dirs = array();
foreach(glob("$path*") as $d)
{
$tmp = explode('.',$d) ;
$k = end($tmp);
if(is_file($d) && ($k ==strtolower($format) ))
{
$dirs[] = $d ;
}
}
return $dirs;
}
/*
Successfully renamed rename/12819320034756.php rename/12819402065296.php
Successfully renamed rename/12819320036890.php rename/12819402067216.php
Successfully renamed rename/12819320037133.php rename/12819402067656.php
Original tutorial on this site, please indicate the source http: //www.bkjia.com/phper/php.html
*/
?>