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.
 
 
 

111 lines
3.2 KiB

<?php
namespace App\Console\Commands;
use App\Services\RenameService;
use function RingCentral\Psr7\str;
use Illuminate\Console\Command;
class RenameTest extends Command {
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'rename:test {path} {prefix} {level=1}';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Command description';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct() {
parent::__construct();
}
/**
* Execute the console command.
*
* @return mixed
*/
public function handle() {
//
$path = $this->argument("path");
$prefix = $this->argument("prefix");
$level = $this->argument("level");
$rename = new RenameService();
$rename->setNameLevel(intval($level));
// renameFileReplaceUseUpperFolderName($path, "_MetArt");exit;
// $this->renameContainSymbol($path);exit;
// $rename->rename($path, $prefix);
// $arr[0] = 1640486381;
// $arr[1] = 1640553754;
// $arr[2] = 1640488544;
// asort($arr);
// dump($rename->getNameLevel());
// dump($arr);exit;
// $rename->rename($path, $prefix);
// recursiveProcessFirstLevelDirectory($path);exit;
// processFirstLevelDirectory($path);exit;
$rename->splitCustomSizeOfFolder($path, $prefix, 500, 33);
exit;
// $rename->rename("/Volumes/WD/tmp/写真图/猫九", "猫九-");
return;
$rename->rename("/Volumes/Backup/images/写真/pcBack/3/", "");
// $rename->rename();
// $rename->mvFiles("/Users/shixuesen/Documents/tmp/秀人旗下《MFStar模范学院》套图及视频写真-TLoB/视频/");
}
public function renameKIDImage($path) {
$files = scandir($path);
// dump($files);exit;
foreach ($files as $file) {
if (str_contains($file, "KID=imgbed,photo&")) {
$pos = strpos($file, ".gif");
if ($pos > 0) {
// dump($pos);
$newFileName = substr($file, 0, $pos + 4);
// dump($newFileName);
$t = 0;
while (is_file($path . DIRECTORY_SEPARATOR . $newFileName)) {
$fileInfo = pathinfo($newFileName);
echo "file " . $newFileName . " already exists\n";
$newFileName = $fileInfo["filename"] . "_" . $t++ . "." . $fileInfo["extension"];
echo "now rename {$file} to " . $newFileName . "\n";
}
// dump("new filename ". $newFileName);
rename($path . DIRECTORY_SEPARATOR . $file, $path . DIRECTORY_SEPARATOR . $newFileName);
}
}
}
}
public function renameContainSymbol($path, $symbol = '?') {
$symbol = "\u{FF1F}";
$symbol = "?";
// echo $symbol;exit;
// $file1 = "请问,这是长胖了吗?--u0bqNwYlvogx089LkDLwLK010412007dnt0E010.mp4";
// echo strpos($file1, $symbol);exit;
$files = scandir($path);
foreach ($files as $file) {
echo $file . "\n";
if (strpos($file, $symbol)) {
$newFileName = str_replace($symbol, " ", $file);
echo "now rename {$file} to " . $newFileName . "\n";
// echo "result is " . rename($path . DIRECTORY_SEPARATOR . $file, $path . DIRECTORY_SEPARATOR . $newFileName);
}
}
}
}