Home >Backend Development >PHP Tutorial >PHP file batch rename file batch rename tool win7 batch rename files batch folder rename ba

PHP file batch rename file batch rename tool win7 batch rename files batch folder rename ba

WBOY
WBOYOriginal
2016-07-29 08:52:551125browse
$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=&#39;color:red&#39;>".$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;
    }

The above introduces the batch renaming of PHP files, including the contents of PHP files and batch renaming. I hope it will be helpful to friends who are interested in PHP tutorials.

Statement:
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