updateseq fix rename?
This commit is contained in:
@@ -58,9 +58,32 @@ function Sync-SequenceFilenames {
|
||||
$newPath = Join-Path $SequenceFolderPath $newName
|
||||
try {
|
||||
if (Test-Path -LiteralPath $newPath) {
|
||||
$existing = Get-Item -LiteralPath $newPath -ErrorAction Stop
|
||||
$sameSize = ($existing.Length -eq $f.Length)
|
||||
$sameTime = ([math]::Abs(($existing.LastWriteTimeUtc - $f.LastWriteTimeUtc).TotalSeconds) -le 1)
|
||||
if ($sameSize -and $sameTime) {
|
||||
Remove-Item -LiteralPath $f.FullName -Force -ErrorAction Stop
|
||||
$collisions++
|
||||
if ($LogFile) { "[$(Get-Date -Format 'yyyy-MM-dd HH:mm:ss')] RENAME DROP duplicate: '$($f.Name)' (matches '$newName')" | Add-Content -LiteralPath $LogFile }
|
||||
continue
|
||||
}
|
||||
|
||||
$archiveDir = Join-Path $SequenceFolderPath '_archive'
|
||||
if (-not (Test-Path -LiteralPath $archiveDir)) {
|
||||
New-Item -ItemType Directory -Path $archiveDir -Force | Out-Null
|
||||
}
|
||||
|
||||
$archiveName = $existing.Name
|
||||
$archivePath = Join-Path $archiveDir $archiveName
|
||||
if (Test-Path -LiteralPath $archivePath) {
|
||||
$stamp = Get-Date -Format 'yyyyMMdd_HHmmss'
|
||||
$baseName = [System.IO.Path]::GetFileNameWithoutExtension($archiveName)
|
||||
$archivePath = Join-Path $archiveDir ("{0}_{1}{2}" -f $baseName, $stamp, $existing.Extension)
|
||||
}
|
||||
|
||||
Move-Item -LiteralPath $existing.FullName -Destination $archivePath -Force -ErrorAction Stop
|
||||
$collisions++
|
||||
if ($LogFile) { "[$(Get-Date -Format 'yyyy-MM-dd HH:mm:ss')] RENAME SKIP collision: '$($f.Name)' -> '$newName'" | Add-Content -LiteralPath $LogFile }
|
||||
continue
|
||||
if ($LogFile) { "[$(Get-Date -Format 'yyyy-MM-dd HH:mm:ss')] RENAME ARCHIVE existing '$($existing.Name)' -> '$archivePath'" | Add-Content -LiteralPath $LogFile }
|
||||
}
|
||||
Rename-Item -LiteralPath $f.FullName -NewName $newName -ErrorAction Stop
|
||||
$renamed++
|
||||
@@ -136,6 +159,27 @@ function Rename-SequencePreviewMp4 {
|
||||
}
|
||||
}
|
||||
|
||||
function Resolve-SequenceName {
|
||||
param(
|
||||
[Parameter(Mandatory)] [System.IO.DirectoryInfo]$Directory
|
||||
)
|
||||
if ($Directory.Name -eq '_CURRENT' -and $Directory.Parent) {
|
||||
return $Directory.Parent.Name
|
||||
}
|
||||
return $Directory.Name
|
||||
}
|
||||
|
||||
function Add-SequenceFolder {
|
||||
param(
|
||||
[Parameter(Mandatory)] [System.IO.DirectoryInfo]$Directory,
|
||||
[Parameter(Mandatory)] [hashtable]$Map
|
||||
)
|
||||
if ($Directory.Name -eq '_archive') { return }
|
||||
$fullPath = $Directory.FullName
|
||||
if ($Map.ContainsKey($fullPath)) { return }
|
||||
$Map[$fullPath] = Resolve-SequenceName -Directory $Directory
|
||||
}
|
||||
|
||||
try {
|
||||
$root = (Get-Location).ProviderPath
|
||||
$logFile = $null
|
||||
@@ -145,24 +189,33 @@ try {
|
||||
"[$(Get-Date -Format 'yyyy-MM-dd HH:mm:ss')] === UpdateSequences started in '$root' ===" | Out-File -LiteralPath $logFile -Encoding UTF8
|
||||
}
|
||||
|
||||
$sequenceFolders = @()
|
||||
$sequenceMap = @{}
|
||||
|
||||
$dailyDirs = Get-ChildItem -LiteralPath $root -Directory -Filter 'daily_*' -ErrorAction SilentlyContinue |
|
||||
Where-Object { $_.Name -ne '_archive' }
|
||||
foreach ($d in $dailyDirs) {
|
||||
$seqDirs = @(Get-ChildItem -LiteralPath $d.FullName -Directory -ErrorAction SilentlyContinue | Where-Object { $_.Name -ne '_archive' })
|
||||
if ($seqDirs.Count -eq 0) {
|
||||
$sequenceFolders += $d
|
||||
Add-SequenceFolder -Directory $d -Map $sequenceMap
|
||||
} else {
|
||||
$sequenceFolders += $seqDirs
|
||||
foreach ($s in $seqDirs) {
|
||||
Add-SequenceFolder -Directory $s -Map $sequenceMap
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$directSeqs = Get-ChildItem -LiteralPath $root -Directory -ErrorAction SilentlyContinue |
|
||||
Where-Object { $_.Name -ne '_archive' -and $_.Name -notlike 'daily_*' }
|
||||
$sequenceFolders += $directSeqs
|
||||
foreach ($seq in $directSeqs) {
|
||||
Add-SequenceFolder -Directory $seq -Map $sequenceMap
|
||||
}
|
||||
|
||||
$sequenceFolders = $sequenceFolders | Sort-Object -Property FullName -Unique
|
||||
$sequenceFolders = $sequenceMap.GetEnumerator() | ForEach-Object {
|
||||
[pscustomobject]@{
|
||||
Path = $_.Key
|
||||
Name = $_.Value
|
||||
}
|
||||
} | Sort-Object -Property Path
|
||||
|
||||
if (-not $sequenceFolders) {
|
||||
Write-Host "No sequence folders found." -ForegroundColor Yellow
|
||||
@@ -180,18 +233,18 @@ try {
|
||||
|
||||
foreach ($seq in $sequenceFolders) {
|
||||
$totalSequences++
|
||||
$renameResult = Sync-SequenceFilenames -SequenceFolderPath $seq.FullName -SequenceName $seq.Name -LogFile $logFile
|
||||
$renameResult = Sync-SequenceFilenames -SequenceFolderPath $seq.Path -SequenceName $seq.Name -LogFile $logFile
|
||||
if ($DebugMode -or $renameResult.Renamed -gt 0 -or $renameResult.Collisions -gt 0 -or $renameResult.Errors -gt 0) {
|
||||
Write-Host "[RENAME]|$($seq.FullName)|$($seq.Name)|checked=$($renameResult.Checked)|renamed=$($renameResult.Renamed)|collisions=$($renameResult.Collisions)|errors=$($renameResult.Errors)" -ForegroundColor Cyan
|
||||
Write-Host "[RENAME]|$($seq.Path)|$($seq.Name)|checked=$($renameResult.Checked)|renamed=$($renameResult.Renamed)|collisions=$($renameResult.Collisions)|errors=$($renameResult.Errors)" -ForegroundColor Cyan
|
||||
}
|
||||
$filesRenamedTotal += $renameResult.Renamed
|
||||
$renameCollisions += $renameResult.Collisions
|
||||
$renameErrors += $renameResult.Errors
|
||||
|
||||
if ($renameResult.FrameCount -gt 0 -and $renameResult.MinFrame -ne $null -and $renameResult.MaxFrame -ne $null) {
|
||||
$mp4Result = Rename-SequencePreviewMp4 -SequenceFolderPath $seq.FullName -SequenceName $seq.Name -StartFrame $renameResult.MinFrame -EndFrame $renameResult.MaxFrame -LogFile $logFile
|
||||
$mp4Result = Rename-SequencePreviewMp4 -SequenceFolderPath $seq.Path -SequenceName $seq.Name -StartFrame $renameResult.MinFrame -EndFrame $renameResult.MaxFrame -LogFile $logFile
|
||||
if ($DebugMode -or $mp4Result.Renamed -gt 0 -or $mp4Result.Collisions -gt 0 -or $mp4Result.Errors -gt 0) {
|
||||
Write-Host "[MP4]|$($seq.FullName)|$($seq.Name)|renamed=$($mp4Result.Renamed)|collisions=$($mp4Result.Collisions)|errors=$($mp4Result.Errors)" -ForegroundColor Cyan
|
||||
Write-Host "[MP4]|$($seq.Path)|$($seq.Name)|renamed=$($mp4Result.Renamed)|collisions=$($mp4Result.Collisions)|errors=$($mp4Result.Errors)" -ForegroundColor Cyan
|
||||
}
|
||||
$mp4RenamedTotal += $mp4Result.Renamed
|
||||
$mp4Collisions += $mp4Result.Collisions
|
||||
|
||||
Reference in New Issue
Block a user