CoachBate commited on
Commit
9bf50c9
·
verified ·
1 Parent(s): b4d635a

Upload fixPaths.ps1

Browse files

fixed my "wan\\" and "video\\" replacements that were supposed to include the double quotes when searching and replacing model paths

Files changed (1) hide show
  1. fixPaths.ps1 +39 -34
fixPaths.ps1 CHANGED
@@ -1,39 +1,47 @@
1
- # Recursively search and replace through *.json workflows for model names or paths that you want to change
2
- # Before updating a file, it will delete it to your recycle bin in case you want to recover it.
 
3
 
4
- # Root directory (modify this and the string replacements for the models)
5
-
6
- $rootPath = "C:\Data\ComfyUser\default\workflows\LTX\"
7
 
8
  $replacements = [ordered]@{
9
-
10
  # 1.1 distilled LTX-2.3
11
- "ltx-2.3-22b-distilled-lora-384.safetensors" = "ltx-2.3-22b-distilled-lora-384-1.1.safetensors"
12
  "ltx-2.3-22b-distilled.safetensors" = "ltx-2.3-22b-distilled-1.1.safetensors"
13
 
 
 
 
 
 
 
 
 
14
  # Transformer (dev)
15
  "LTXVideo\v2\ltx-2.3-22b-dev_transformer_only_fp8_scaled.safetensors" = "ltx-2-3-22b-dev_transformer_only_fp8_input_scaled.safetensors"
16
  "LTXVideo\\v2\\ltx-2.3-22b-dev_transformer_only_fp8_scaled.safetensors" = "ltx-2-3-22b-dev_transformer_only_fp8_input_scaled.safetensors"
17
 
18
  # LoRA (path cleanup)
19
- "LTX\LTX-2\ltx-2.3-22b-distilled-lora-384.safetensors" = "ltx-2.3-22b-distilled-lora-384.safetensors"
20
- "LTX\\LTX-2\\ltx-2.3-22b-distilled-lora-384.safetensors" = "ltx-2.3-22b-distilled-lora-384.safetensors"
21
 
22
- # Spatial upscaler (FIXED)
23
  "ltx-2.3-spatial-upscaler-x2-1.0.safetensors" = "ltx-2.3-spatial-upscaler-x2-1.1.safetensors"
24
 
25
  # Distilled transformer
26
  "LTXVideo\v2\ltx-2.3-22b-distilled_transformer_only_fp8_scaled.safetensors" = "ltx-2.3-22b-distilled_transformer_only_fp8_input_scaled_v3.safetensors"
27
  "LTXVideo\\v2\\ltx-2.3-22b-distilled_transformer_only_fp8_scaled.safetensors" = "ltx-2.3-22b-distilled_transformer_only_fp8_input_scaled_v3.safetensors"
28
 
29
- # VAE cleanup - on my system it wouldn't pick it up in vae_approx so I personally have these uncommented
30
  "vae_approx\taeltx2_3.safetensors" = "taeltx2_3.safetensors"
31
  "vae_approx\\taeltx2_3.safetensors" = "taeltx2_3.safetensors"
32
 
33
  # Gemma
34
  "gemma_3_12B_it_fpmixed.safetensors" = "gemma_3_12B_it_fp8_scaled.safetensors"
35
 
36
- # Additional VAE replacements
37
  "LTX23_audio_vae_bf16_KJ.safetensors" = "LTX23_audio_vae_bf16.safetensors"
38
  "LTX23_video_vae_bf16_KJ.safetensors" = "LTX23_video_vae_bf16.safetensors"
39
  }
@@ -41,28 +49,16 @@ $replacements = [ordered]@{
41
  Add-Type -AssemblyName Microsoft.VisualBasic
42
 
43
  function Get-LiteralMatchCount {
44
- param (
45
- [string]$Text,
46
- [string]$Search
47
- )
48
-
49
- if ([string]::IsNullOrEmpty($Search)) {
50
- return 0
51
- }
52
-
53
  $count = 0
54
  $startIndex = 0
55
-
56
  while ($true) {
57
  $index = $Text.IndexOf($Search, $startIndex, [System.StringComparison]::Ordinal)
58
- if ($index -lt 0) {
59
- break
60
- }
61
-
62
  $count += 1
63
  $startIndex = $index + $Search.Length
64
  }
65
-
66
  return $count
67
  }
68
 
@@ -75,31 +71,40 @@ foreach ($file in $files) {
75
 
76
  foreach ($oldValue in $replacements.Keys) {
77
  $newValue = $replacements[$oldValue]
78
-
79
  $count = Get-LiteralMatchCount -Text $content -Search $oldValue
80
 
81
  if ($count -gt 0) {
82
  $content = $content.Replace($oldValue, $newValue)
83
-
84
- Write-Host "[$($file.Name)] Replaced $count occurrence(s):"
85
- Write-Host " OLD: $oldValue"
86
- Write-Host " NEW: $newValue"
87
  $changed = $true
88
  }
89
  }
90
 
91
  if ($changed -and $content -ne $originalContent) {
92
  try {
93
- # Send original file to Recycle Bin
 
 
 
 
 
 
94
  [Microsoft.VisualBasic.FileIO.FileSystem]::DeleteFile(
95
  $file.FullName,
96
  [Microsoft.VisualBasic.FileIO.UIOption]::OnlyErrorDialogs,
97
  [Microsoft.VisualBasic.FileIO.RecycleOption]::SendToRecycleBin
98
  )
99
 
100
- # Write updated content back to original path
101
  Set-Content -Path $file.FullName -Value $content -Encoding UTF8
102
 
 
 
 
 
 
 
 
103
  Write-Host "Updated: $($file.FullName)"
104
  Write-Host ""
105
  }
 
1
+ # Recursively search and replace through *.json workflows
2
+ # Preserves original Created and Modified timestamps
3
+ # Targets specific "video\ paths starting with a literal double quote
4
 
5
+ # --- Configuration ---
6
+ $rootPath = "C:\Data\ComfyUser\default\workflows\"
7
+ $preserveTimestamps = $true
8
 
9
  $replacements = [ordered]@{
 
10
  # 1.1 distilled LTX-2.3
11
+ "ltx-2.3-22b-distilled-lora-384.safetensors" = "ltx-2.3-22b-distilled-lora-384-1.1.safetensors"
12
  "ltx-2.3-22b-distilled.safetensors" = "ltx-2.3-22b-distilled-1.1.safetensors"
13
 
14
+ # Directory migrations
15
+ "<lora:wan\\" = "<lora:wan2.2\\"
16
+ "<lora:video\\" = "<lora:wan2.1\\"
17
+
18
+ # Specific targeted replacement: matches literal "video\
19
+ '"video\\' = '"wan2.1\\'
20
+ '"wan\\' = '"wan2.2\\'
21
+
22
  # Transformer (dev)
23
  "LTXVideo\v2\ltx-2.3-22b-dev_transformer_only_fp8_scaled.safetensors" = "ltx-2-3-22b-dev_transformer_only_fp8_input_scaled.safetensors"
24
  "LTXVideo\\v2\\ltx-2.3-22b-dev_transformer_only_fp8_scaled.safetensors" = "ltx-2-3-22b-dev_transformer_only_fp8_input_scaled.safetensors"
25
 
26
  # LoRA (path cleanup)
27
+ "LTX\LTX-2\ltx-2.3-22b-distilled-lora-384.safetensors" = "ltx-2.3-22b-distilled-lora-384-1.1.safetensors"
28
+ "LTX\\LTX-2\\ltx-2.3-22b-distilled-lora-384.safetensors" = "ltx-2.3-22b-distilled-lora-384-1.1.safetensors"
29
 
30
+ # Spatial upscaler
31
  "ltx-2.3-spatial-upscaler-x2-1.0.safetensors" = "ltx-2.3-spatial-upscaler-x2-1.1.safetensors"
32
 
33
  # Distilled transformer
34
  "LTXVideo\v2\ltx-2.3-22b-distilled_transformer_only_fp8_scaled.safetensors" = "ltx-2.3-22b-distilled_transformer_only_fp8_input_scaled_v3.safetensors"
35
  "LTXVideo\\v2\\ltx-2.3-22b-distilled_transformer_only_fp8_scaled.safetensors" = "ltx-2.3-22b-distilled_transformer_only_fp8_input_scaled_v3.safetensors"
36
 
37
+ # VAE cleanup
38
  "vae_approx\taeltx2_3.safetensors" = "taeltx2_3.safetensors"
39
  "vae_approx\\taeltx2_3.safetensors" = "taeltx2_3.safetensors"
40
 
41
  # Gemma
42
  "gemma_3_12B_it_fpmixed.safetensors" = "gemma_3_12B_it_fp8_scaled.safetensors"
43
 
44
+ # Additional VAE replacements
45
  "LTX23_audio_vae_bf16_KJ.safetensors" = "LTX23_audio_vae_bf16.safetensors"
46
  "LTX23_video_vae_bf16_KJ.safetensors" = "LTX23_video_vae_bf16.safetensors"
47
  }
 
49
  Add-Type -AssemblyName Microsoft.VisualBasic
50
 
51
  function Get-LiteralMatchCount {
52
+ param ([string]$Text, [string]$Search)
53
+ if ([string]::IsNullOrEmpty($Search)) { return 0 }
 
 
 
 
 
 
 
54
  $count = 0
55
  $startIndex = 0
 
56
  while ($true) {
57
  $index = $Text.IndexOf($Search, $startIndex, [System.StringComparison]::Ordinal)
58
+ if ($index -lt 0) { break }
 
 
 
59
  $count += 1
60
  $startIndex = $index + $Search.Length
61
  }
 
62
  return $count
63
  }
64
 
 
71
 
72
  foreach ($oldValue in $replacements.Keys) {
73
  $newValue = $replacements[$oldValue]
 
74
  $count = Get-LiteralMatchCount -Text $content -Search $oldValue
75
 
76
  if ($count -gt 0) {
77
  $content = $content.Replace($oldValue, $newValue)
78
+ Write-Host "[$($file.Name)] Replaced $count occurrence(s): $oldValue -> $newValue"
 
 
 
79
  $changed = $true
80
  }
81
  }
82
 
83
  if ($changed -and $content -ne $originalContent) {
84
  try {
85
+ # Capture timestamps
86
+ if ($preserveTimestamps) {
87
+ $origCreated = $file.CreationTime
88
+ $origModified = $file.LastWriteTime
89
+ }
90
+
91
+ # Move to Recycle Bin
92
  [Microsoft.VisualBasic.FileIO.FileSystem]::DeleteFile(
93
  $file.FullName,
94
  [Microsoft.VisualBasic.FileIO.UIOption]::OnlyErrorDialogs,
95
  [Microsoft.VisualBasic.FileIO.RecycleOption]::SendToRecycleBin
96
  )
97
 
98
+ # Write new file
99
  Set-Content -Path $file.FullName -Value $content -Encoding UTF8
100
 
101
+ # Restore timestamps
102
+ if ($preserveTimestamps) {
103
+ $newFile = Get-Item -Path $file.FullName
104
+ $newFile.CreationTime = $origCreated
105
+ $newFile.LastWriteTime = $origModified
106
+ }
107
+
108
  Write-Host "Updated: $($file.FullName)"
109
  Write-Host ""
110
  }