$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教程有興趣的朋友有所幫助。