Home  >  Article  >  Backend Development  >  How to batch modify file names in php

How to batch modify file names in php

coldplay.xixi
coldplay.xixiOriginal
2020-08-05 11:14:023029browse

php method to implement batch modification of file names: first use the function [rename] to implement, the code is [$path = pathinfo($curDir); rename($curDir,$newname)]; then run the code, and Just open the folder again.

How to batch modify file names in php

php method to implement batch modification of file names:

Then we can use the rename function of php to Good implementation,

My index.php and img folders are using one layer, so I will use relative paths as an example

How to batch modify file names in php

index. The source code of php is as follows:

将名为:".$fn."\n\r";
      $curDir = $dirname.'/'.$fn;
   if(is_dir($curDir)){
      fRename($curDir);
   }else{
      $path = pathinfo($curDir);
      //改成你自己想要的新名字
      $newname = $path['dirname'].'/'.$i.'.'.$path['extension'];
      echo "替换成:".$i.'.'.$path['extension']."\r\n";
      rename($curDir,$newname);
      $i++;
   }
  }
 }
}
//给出一个目录名称可以是相对路径,也可以是绝对路径
fRename('img\Gastroenterology');
exit();
?>

Run the code and the screenshot is as follows:

How to batch modify file names in php

Then open the picture folder:

How to batch modify file names in php

Related video recommendations: PHP programming from entry to proficiency

The above is the detailed content of How to batch modify file names in php. For more information, please follow other related articles on the PHP Chinese website!

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