$format ='jpg'; $path ='C:/Users/12759/Desktop/5.30.120.0'; $files = $this->getfile($path,$format); foreach( $files as $v ) { /* //$tv = basename($v); //dd($tv);*/ $aa = pathinfo($v); //dd($aa); //list($name,$ext) = explode('.',$tv); //$newname =$path.time().mt_rand(1,10000).'.'.$ext;*/ $newname = md5($aa['filename']).'.'.$aa['extension']; //dd($newname); /* if(rename($v,$newname)) { echo '成功将'.$v.'重命名'.$newname.'<br>'; }*/ rename($path.'/'.$v,$path.'/'.$newname); /*echo '成功将'.$v.'重命名'.$newname.'<br>'; */ echo "<span style="'color:red'">".$v."</span>"."--------------".$newname."<br>"; } public function getfile($dirname,$format) { $dirs = array(); $handle = opendir($dirname); while(($fn = readdir($handle))!==false){ if($fn!='.'&&$fn!='..'){ $curDir = $dirname.'/'.$fn; $path = pathinfo($curDir); $dirs[] = $path['basename']; } } return $dirs; }
以上就介绍了php文件批量重命名,包括了php文件,批量重命名方面的内容,希望对PHP教程有兴趣的朋友有所帮助。