php文件夹下文件批量重命名

<?php
header("Content-type:text/html;charset=utf-8");

$dir = __DIR__.'./color/';
$file_arr = scandir($dir);
unset($file_arr[0]);
unset($file_arr[1]);
$file_arr = array_values($file_arr);

$n = count($file_arr);
for ($i = 0; $i < $n; ++$i){
    $title = sprintf('color_%02s', $i + 1);
    $old_file_name = $dir.$file_arr[$i];
    $new_file_name = $title.strrchr($file_arr[$i],'.');
    rename($old_file_name, $new_file_name);
}

相关文章:

  • 2021-12-26
  • 2022-01-15
  • 2021-08-09
  • 2021-11-29
猜你喜欢
  • 2021-06-19
  • 2022-12-23
  • 2022-12-23
  • 2021-09-13
  • 2022-12-23
  • 2021-12-27
  • 2021-11-18
相关资源
相似解决方案