php 批量重命名文件

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

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

        } else {

        }

        if(strpos($entry, '.htm')){
            // echo $paths.$entry;
            // echo "原 ".$entry;
            
            echo "
"; // $newname = strtr($entry, '-t=18121111.htm', ''); $newname = str_replace('-t=18121111.htm', '', $entry); echo "新 ".$newname; echo "
"; rename($paths.$entry, $paths.$newname); } } $d->close(); echo "done"; }

你可能感兴趣的:(php 批量重命名文件)