如何用php批量重命名文件

/**
 * php 批量重命名文件
 *
 * @return void
 */
function renamefiles()
{
    $paths = "/path";
    $d = dir($paths);
    while (false !== ($entry = $d->read())) {

        if($entry == '.' || $entry == '..'){

        } else {

        }

        if(strpos($entry, '.mp4')){
            // echo $paths.$entry;
            // echo "原 ".$entry;

            echo "<br>";

            // $newname = strtr($entry, '-t=18121111.htm', '');  
            /*把字符串 "Hello world!" 中的字符 "world" 替换为 "Shanghai":
                echo str_replace("world","Shanghai","Hello world!");
                substr(string,start,length)*/

            $newname = substr($entry, 0, 2).".mp4";

            echo $newname;

            echo "<br>";       

            rename($paths.$entry, $paths.$newname);
        }


    }
    $d->close();
    echo "done";
}