1. 程式人生 > 其它 >【PHP】批量遞迴修改資料夾名或檔名

【PHP】批量遞迴修改資料夾名或檔名

<?php

    //定義生成器提升效能
    function generate($path)
    {
        $list = scandir($path);
        if(is_null($list) || empty($list)) {
            return null;
        }
        foreach($list as $k=>$v){
            yield $v;
        }
    }

    function multi($path)
    {
        $value = generate($path
); if(is_null($value)){ return; } //使用正則修改檔名 $regexp = '/【.*?】/'; foreach($value as $k => $v){ if(!in_array($v,['.','..',__FILE__])){ $new = preg_replace($regexp,'',$v); //windows目錄下使用\斜線 rename
($path.'\\'.$v,$path.'\\'.$new); if(is_dir($path.'\\'.$new)){ multi($path.'\\'.$new); } } } } multi(__DIR__);

本文來自部落格園,作者:程式設計混子,轉載請註明原文連結:https://www.cnblogs.com/Qyehui/p/15137934.html