那就这样吧的头像-EoHut 电光小屋
这家伙很懒,什么都没有写...

15天前
$BandizipPath = "C:\Program Files\Bandizip\Bandizip.exe" $BandizipCliPath = Join-Path (Split-Path $BandizipPath -Parent) "bz.exe" $ParentFolder = $PSScriptRoot $Passwords = @("猫里奥小新", "小猫喝奶啤") $LXNDPassword = "LXNDLXND" $NewFlowFolderPrefixes = @("LXNDG", "LXNDD") function Invoke-BandizipExtract { param( [string]$ArchivePath, [string]$OutputDir, [string]$Password = "" ) $Args = @("x", "-o:$OutputDir", "-y") if ($Password) { $Args += "-p:$Password" } $Args += $ArchivePath & $BandizipCliPath @Args | Out-Null } function Remove-MatchingFiles { param( [string]$TargetDir, [string[]]$Patterns ) foreach ($Pattern in $Patterns) { Get-ChildItem -Path $TargetDir -Filter $Pattern -File -ErrorAction SilentlyContinue | Remove-Item -Force -ErrorAction SilentlyContinue } } function Get-FirstMatchingFile { param([string]$TargetDir, [string[]]$Filters) foreach ($Filter in $Filters) { $File = Get-ChildItem -Path $TargetDir -Filter $Filter -File -ErrorAction SilentlyContinue | Select-Object -First 1 if ($File) { return $File } } } function Rename-FileSafely { param([string]$FilePath, [string]$NewName) $NewPath = Join-Path (Split-Path $FilePath -Parent) $NewName if (Test-Path $NewPath) { Remove-Item $NewPath -Force } Rename-Item -Path $FilePath -NewName $NewName -Force return $NewPath } function Test-NewFlowFolder { param([string]$FolderName, [string[]]$TargetDirs) foreach ($Prefix in $NewFlowFolderPrefixes) { if ($FolderName -like "$Prefix*") { return $true } } foreach ($TargetDir in $TargetDirs) { if (Get-ChildItem -Path $TargetDir -Filter "*.7z.001" -File -ErrorAction SilentlyContinue | Select-Object -First 1) { return $true } } return $false } function Expand-LXNDGPackage { param([string]$TargetDir) Write-Host " [LXNDG] 处理目录: $(Split-Path $TargetDir -Leaf)" -ForegroundColor White $VolumeFile = Get-FirstMatchingFile -TargetDir $TargetDir -Filters @("*.7z.001") if (-not $VolumeFile) { Write-Host " -> 未找到分卷压缩包" -ForegroundColor Yellow return } Write-Host " [1/4] 正在解压分卷..." -ForegroundColor Gray Invoke-BandizipExtract -ArchivePath $VolumeFile.FullName -OutputDir $TargetDir -Password $LXNDPassword $Mp4File = Get-FirstMatchingFile -TargetDir $TargetDir -Filters @("*.mp4") if (-not $Mp4File) { Write-Host " -> 未找到 MP4 文件" -ForegroundColor Yellow return } $ZipName = $Mp4File.BaseName + ".zip" $ZipPath = Rename-FileSafely -FilePath $Mp4File.FullName -NewName $ZipName Write-Host " [2/4] MP4 -> ZIP 后继续解压..." -ForegroundColor Gray Invoke-BandizipExtract -ArchivePath $ZipPath -OutputDir $TargetDir -Password $LXNDPassword $DirtyFile = Get-ChildItem -Path $TargetDir -File | Where-Object { $_.Name -like "*删除汉字*" } | Select-Object -First 1 if (-not $DirtyFile) { Write-Host " -> 未找到最终压缩包" -ForegroundColor Yellow return } $CleanName = $DirtyFile.Name -replace "删除汉字", "" $CleanPath = Rename-FileSafely -FilePath $DirtyFile.FullName -NewName $CleanName Write-Host " [3/4] 最终压缩包改名并解压..." -ForegroundColor Gray Invoke-BandizipExtract -ArchivePath $CleanPath -OutputDir $TargetDir -Password $LXNDPassword Write-Host " [4/4] 清理压缩包..." -ForegroundColor Gray Remove-MatchingFiles -TargetDir $TargetDir -Patterns @("*.7z", "*.7z.00*", "*.zip", "*.rar", "*删除汉字*") Write-Host " -> LXNDG 流程完成" -ForegroundColor Green } Write-Host "========================================" -ForegroundColor Cyan Write-Host " 先解压,后删除 (最稳妥)" -ForegroundColor Cyan Write-Host "========================================" -ForegroundColor Cyan if (-not (Test-Path $BandizipCliPath)) { Write-Host "[错误] 找不到 Bandizip 控制台程序: $BandizipCliPath" -ForegroundColor Red pause exit } $SubFolders = Get-ChildItem -Path $ParentFolder -Directory foreach ($Folder in $SubFolders) { Write-Host "`n[文件夹] $($Folder.Name)" -ForegroundColor White $VariantFolders = Get-ChildItem -Path $Folder.FullName -Directory | Where-Object { $_.Name -in @("A", "P") } $Targets = if ($VariantFolders) { $VariantFolders.FullName } else { @($Folder.FullName) } if (Test-NewFlowFolder -FolderName $Folder.Name -TargetDirs $Targets) { foreach ($TargetDir in $Targets) { if (Get-FirstMatchingFile -TargetDir $TargetDir -Filters @("*.7z.001")) { Expand-LXNDGPackage -TargetDir $TargetDir } } continue } Set-Location $Folder.FullName $CurrentDir = $Folder.FullName $AllDone = $false # 标记是否全部完成 # ========================================================= # 第一步:解压初始分卷 # ========================================================= $PartFile = Get-FirstMatchingFile -TargetDir $CurrentDir -Filters @("*.part1.rar", "*.rar") if ($PartFile) { Write-Host " [1/5] 正在解压分卷..." -ForegroundColor Gray Invoke-BandizipExtract -ArchivePath $PartFile.FullName -OutputDir $CurrentDir $JpgFile = Get-FirstMatchingFile -TargetDir $CurrentDir -Filters @("*.JPG") if ($JpgFile) { $NewName = $JpgFile.BaseName + ".rar" Rename-FileSafely -FilePath $JpgFile.FullName -NewName $NewName | Out-Null Write-Host " [2/5] JPG -> RAR 重命名成功" -ForegroundColor Green } else { Set-Location $ParentFolder; continue } } else { Set-Location $ParentFolder; continue } # ========================================================= # 第二步:第一次带密码解压 # ========================================================= $RarStage1 = Get-ChildItem -Filter "*.rar" | Where-Object { $_.Name -notlike "*.part*" } | Select-Object -First 1 if ($RarStage1) { $Success = $false Write-Host " [3/5] 正在尝试第一次密码解压..." -ForegroundColor Gray foreach ($Pwd in $Passwords) { Invoke-BandizipExtract -ArchivePath $RarStage1.FullName -OutputDir $CurrentDir -Password $Pwd $DirtyFile = Get-ChildItem | Where-Object { $_.Name -like "*删除汉字*" } | Select-Object -First 1 if ($DirtyFile) { $Success = $true Write-Host " -> 密码正确 ($Pwd)" -ForegroundColor Green $CleanName = $DirtyFile.Name -replace "删除汉字", "" Rename-FileSafely -FilePath $DirtyFile.FullName -NewName $CleanName | Out-Null break } } if (-not $Success) { Set-Location $ParentFolder; continue } } # ========================================================= # 第三步:最后一次解压 # ========================================================= $RarStage2 = Get-ChildItem -Filter "*.rar" | Where-Object { $_.Name -notlike "*.part*" } | Select-Object -First 1 if ($RarStage2) { $Success = $false Write-Host " [4/5] 正在尝试最终解压..." -ForegroundColor Gray foreach ($Pwd in $Passwords) { Invoke-BandizipExtract -ArchivePath $RarStage2.FullName -OutputDir $CurrentDir -Password $Pwd # 检查是否成功(只要文件夹里除了这个rar还有别的东西,或者rar消失了) $CheckFile = Get-ChildItem | Where-Object { $_.Name -ne $RarStage2.Name -and $_.Name -notlike "*.part*" } if ($CheckFile) { $Success = $true $AllDone = $true Write-Host " -> 密码正确 ($Pwd)" -ForegroundColor Green break } } if ($Success) { Write-Host " [5/5] 全部解压成功!" -ForegroundColor Green } } # ========================================================= # 【新增】最后一步:统一删除所有压缩包 # ========================================================= if ($AllDone) { Write-Host " [清理] 正在删除所有压缩包文件..." -ForegroundColor Gray Remove-MatchingFiles -TargetDir $CurrentDir -Patterns @("*.part*.rar", "*.rar") Write-Host " [完成] 清理完毕!" -ForegroundColor Green } Set-Location $ParentFolder } Write-Host "`n脚本执行完毕。" -ForegroundColor Cyan pause