You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

47 lines
1.3 KiB

<?php
namespace App\Services;
class RenameService
{
public function rename($baseDir = "/Volumes/intel660p/image/xg1")
{
if (!is_dir($baseDir)) {
return;
}
$this->parseDir($baseDir);
}
private function parseDir($dir)
{
if (!is_dir($dir)) {
return;
}
$files = scandir($dir);
foreach ($files as $file) {
// dump($file);
if ($file == "." || $file == ".." || $file == ".DS_Store" || $file == ".tmp.drivedownload") {
continue;
}
if (is_dir($dir . "/" .$file)) {
$this->parseDir($dir . "/" . $file);
}
if (is_file($dir . "/" .$file) && (pathinfo($file, PATHINFO_EXTENSION) == "jpg" || pathinfo($file, PATHINFO_EXTENSION) == "jpeg" || pathinfo($file, PATHINFO_EXTENSION) == "mp4")) {
echo $dir;
echo "\n";
echo $file;
$dirList = explode("/", $dir);
$filePrefix = array_pop($dirList);
if (!str_contains($file, $filePrefix)) {
rename($dir . "/" . $file, $dir. "/". $filePrefix. "-" . $file);
}
echo "\n";
// exit;
}
}
}
}