PHP batch rename_PHP tutorial

WBOY
Release: 2016-07-20 11:08:32
Original
1347 people have browsed it

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
*/
?>


www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/444860.htmlTechArticlephp batch renaming This program is divided into simple single file renaming, and getfile can be used to achieve batch renaming of files. Named, $path is the directory you want to rename, it can put the directory pointed to in the specified directory...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!