How to traverse a folder and modify the name of the file in the folder: first read the folder; then traverse the folder through the "foreach($temp as $v){...}" method; finally pass The "@rename($a,$new_name);" method can be used to modify the file name.
The operating environment of this article: windows7 system, PHP7.1 version, DELL G3 computer
How does php traverse the folder and modify the files under the folder? Name?
php traverses the folder file name and changes the file name
$a","
"; //把文件夹红名输出 list_file($a);//因为是文件夹所以再次调用自己这个函数,把这个文件夹下的文件遍历出来 }else{ echo $a."
"; $info = pathinfo($a); //$file_name = basename($a,'.'.$info['extension']); $kuozhan=$info["extension"]; $lujing=$info["dirname"]; $mingcheng=$info["filename"]; if($mingcheng!="4" and $mingcheng!="5"){ $mingcheng_new=base64_encode($mingcheng); $new_name=$lujing."/".$mingcheng_new.".".$kuozhan; @rename($a,$new_name); } //var_dump($info); //echo "*****".$file_name; } } } list_file('F:/MYOA'); ?>
[Recommended learning:PHP video tutorial]
The above is the detailed content of How to traverse the folder and modify the file name in the folder in php. For more information, please follow other related articles on the PHP Chinese website!