ComfyUI_Utilities / fixPaths.ps1
CoachBate's picture
Upload fixPaths.ps1
9bf50c9 verified
# Recursively search and replace through *.json workflows
# Preserves original Created and Modified timestamps
# Targets specific "video\ paths starting with a literal double quote
# --- Configuration ---
$rootPath = "C:\Data\ComfyUser\default\workflows\"
$preserveTimestamps = $true
$replacements = [ordered]@{
# 1.1 distilled LTX-2.3
"ltx-2.3-22b-distilled-lora-384.safetensors" = "ltx-2.3-22b-distilled-lora-384-1.1.safetensors"
"ltx-2.3-22b-distilled.safetensors" = "ltx-2.3-22b-distilled-1.1.safetensors"
# Directory migrations
"<lora:wan\\" = "<lora:wan2.2\\"
"<lora:video\\" = "<lora:wan2.1\\"
# Specific targeted replacement: matches literal "video\
'"video\\' = '"wan2.1\\'
'"wan\\' = '"wan2.2\\'
# Transformer (dev)
"LTXVideo\v2\ltx-2.3-22b-dev_transformer_only_fp8_scaled.safetensors" = "ltx-2-3-22b-dev_transformer_only_fp8_input_scaled.safetensors"
"LTXVideo\\v2\\ltx-2.3-22b-dev_transformer_only_fp8_scaled.safetensors" = "ltx-2-3-22b-dev_transformer_only_fp8_input_scaled.safetensors"
# LoRA (path cleanup)
"LTX\LTX-2\ltx-2.3-22b-distilled-lora-384.safetensors" = "ltx-2.3-22b-distilled-lora-384-1.1.safetensors"
"LTX\\LTX-2\\ltx-2.3-22b-distilled-lora-384.safetensors" = "ltx-2.3-22b-distilled-lora-384-1.1.safetensors"
# Spatial upscaler
"ltx-2.3-spatial-upscaler-x2-1.0.safetensors" = "ltx-2.3-spatial-upscaler-x2-1.1.safetensors"
# Distilled transformer
"LTXVideo\v2\ltx-2.3-22b-distilled_transformer_only_fp8_scaled.safetensors" = "ltx-2.3-22b-distilled_transformer_only_fp8_input_scaled_v3.safetensors"
"LTXVideo\\v2\\ltx-2.3-22b-distilled_transformer_only_fp8_scaled.safetensors" = "ltx-2.3-22b-distilled_transformer_only_fp8_input_scaled_v3.safetensors"
# VAE cleanup
"vae_approx\taeltx2_3.safetensors" = "taeltx2_3.safetensors"
"vae_approx\\taeltx2_3.safetensors" = "taeltx2_3.safetensors"
# Gemma
"gemma_3_12B_it_fpmixed.safetensors" = "gemma_3_12B_it_fp8_scaled.safetensors"
# Additional VAE replacements
"LTX23_audio_vae_bf16_KJ.safetensors" = "LTX23_audio_vae_bf16.safetensors"
"LTX23_video_vae_bf16_KJ.safetensors" = "LTX23_video_vae_bf16.safetensors"
}
Add-Type -AssemblyName Microsoft.VisualBasic
function Get-LiteralMatchCount {
param ([string]$Text, [string]$Search)
if ([string]::IsNullOrEmpty($Search)) { return 0 }
$count = 0
$startIndex = 0
while ($true) {
$index = $Text.IndexOf($Search, $startIndex, [System.StringComparison]::Ordinal)
if ($index -lt 0) { break }
$count += 1
$startIndex = $index + $Search.Length
}
return $count
}
$files = Get-ChildItem -Path $rootPath -Recurse -Filter *.json -File
foreach ($file in $files) {
$content = Get-Content -Path $file.FullName -Raw -Encoding UTF8
$originalContent = $content
$changed = $false
foreach ($oldValue in $replacements.Keys) {
$newValue = $replacements[$oldValue]
$count = Get-LiteralMatchCount -Text $content -Search $oldValue
if ($count -gt 0) {
$content = $content.Replace($oldValue, $newValue)
Write-Host "[$($file.Name)] Replaced $count occurrence(s): $oldValue -> $newValue"
$changed = $true
}
}
if ($changed -and $content -ne $originalContent) {
try {
# Capture timestamps
if ($preserveTimestamps) {
$origCreated = $file.CreationTime
$origModified = $file.LastWriteTime
}
# Move to Recycle Bin
[Microsoft.VisualBasic.FileIO.FileSystem]::DeleteFile(
$file.FullName,
[Microsoft.VisualBasic.FileIO.UIOption]::OnlyErrorDialogs,
[Microsoft.VisualBasic.FileIO.RecycleOption]::SendToRecycleBin
)
# Write new file
Set-Content -Path $file.FullName -Value $content -Encoding UTF8
# Restore timestamps
if ($preserveTimestamps) {
$newFile = Get-Item -Path $file.FullName
$newFile.CreationTime = $origCreated
$newFile.LastWriteTime = $origModified
}
Write-Host "Updated: $($file.FullName)"
Write-Host ""
}
catch {
Write-Host "ERROR updating: $($file.FullName)"
Write-Host " $($_.Exception.Message)"
Write-Host ""
}
}
}
Write-Host "Done."