大容量重命名名称中包含某些文本的文件


Bulk renaming files where some text in the name

我在实时服务器上的一个文件夹中批量重命名文件时犯了一个错误。基本上,我已经丢失了大量.jpeg文件的扩展名。现在它们看起来像file1jpegfile2jpeg

如何扫描整个文件夹并将以"jpeg"结尾的文件名替换为".jpeg",如file1.jpeg

LE。某些文件的名称中可能已经有点(".")。

非常感谢!

这应该可以工作。对我来说效果很好

<?php
    $allFiles = scandir('../php/'); // REPLACE WITH YOUR DIRECTORY

    foreach($allFiles as $file) {
        $pos = strpos($file, 'php'); // REPLACE PHP WITH YOUR EXTENSION
        $newstring = substr_replace($file, '.', $pos, 0);

        rename("../php/$file", "../php/".$newstring);
    }
?>

以下是如何开始:

<?php
   $string = "filejpeg";
   $pos = strpos($string, 'jpeg');
   $newstring = substr_replace($string, '.', $pos, 0);
    var_dump($newstring);
?>