diff --git a/.specstory/history/2025-08-19_18-08Z-rename-images-to-match-folder-names.md b/.specstory/history/2025-08-19_18-08Z-rename-images-to-match-folder-names.md index 2a82ac3..4374abf 100644 --- a/.specstory/history/2025-08-19_18-08Z-rename-images-to-match-folder-names.md +++ b/.specstory/history/2025-08-19_18-08Z-rename-images-to-match-folder-names.md @@ -686,3 +686,62 @@ I'll implement the two edits now: add a pre-copy wipe in the PowerShell script, --- +_**User**_ + +let's make it so @UpgradeSeqBatches.ps1 works with @UpdateSequences.bat, @UpdateSequences.ps1, AND @UpdateAllSequences.bat + +--- + +_**Assistant**_ + +
Thought Process**Considering file updates and counters** + +I'm thinking about using distinct counters for each filename while also keeping a single count. When copying the ps1 file, I need to ensure it properly handles folders, updating all required scripts, even if they exist. The goal is to work with all three filenames, updating where necessary. + +I'll print counts and summaries in a colorful style while preserving the original indentation. To make this smoother, I should implement a helper function for copying files and catching exceptions consistently. +**Modifying the script for clarity** + +I want to make a minimal modification: I’ll add a variable for the path to "UpdateAllSequences.bat" and include an existence check. + +Next, I'll define the target files, including both the bat and ps1 files. My plan is to iterate through these targets using `Get-ChildItem -Recurse` to find them, ensuring I copy each one appropriately. Instead of the current directory logic, I’ll implement a more clear per-target copying approach. However, I need to make sure to maintain the original functionality that lists all found target files. +**Restructuring file updates for clarity** + +The task requires working with three files, so I’ll restructure my approach into three loops while maintaining readability. First, I’ll define the source variables and check their existence—failing if any are missing. + +Next, I’ll print a section for each file, starting with "Updating UpdateSequences.bat" and gathering targets to copy and track counts. For the ps1 file, I want to update only where any of the three files exist. Alternatively, I could copy the ps1 to the same directory as the bat, even if that directory is initially missing. +**Enhancing script updates and error handling** + +I'm planning to search for ps1 file occurrences, and while it's okay to copy to directories lacking it, I’ll restrict the new changes to only copy where the file already exists. + +I’ll provide a summary for each file type and utilize the existing error handling. Now, I’ll edit UpgradeSeqBatches.ps1 and make the echoed messages more concise. + +I'll apply the patch and run read_lints, checking for any flagged issues. It’s essential to include a status update before making tool calls as per the guidelines, even if we previously missed that. +**Implementing updates and error handling** + +I’ll include a brief micro-update just before the tool calls, and we’ll apply the patch as planned. Since we’re modifying an existing script, I’ll skip creating a todo list. + +To handle edge cases, I’ll structure the code to loop through an array of file specifications. I’ll set up item details for UpdateSequences.bat, UpdateSequences.ps1, and UpdateAllSequences.bat. + +For each item, I’ll gather targets using `Get-ChildItem` and print the found counts. Then, I’ll copy each file with proper error handling and keep track of successes and failures. Finally, I’ll print a summary while ensuring consistent formatting with colored outputs.
+ +--- + +I'll update `UpgradeSeqBatches.ps1` to handle copying three files: `UpdateSequences.bat`, `UpdateSequences.ps1`, and `UpdateAllSequences.bat`, updating each wherever that file exists under the root, with per-file counts and summaries. + +--- + + + +--- + +- UpgradeSeqBatches.ps1 now updates all three files where they exist under `A:\1 Amazon_Active_Projects`: + - `UpdateSequences.bat` + - `UpdateSequences.ps1` + - `UpdateAllSequences.bat` +- Per-file sections list targets, attempt forced copy, and emit individual and per-file summaries. +- Added an overall summary across all three for quick totals. + +Run it as before; it will handle all three script types. + +--- + diff --git a/UpgradeSeqBatches.ps1 b/UpgradeSeqBatches.ps1 index e7c2401..4a22eb4 100644 --- a/UpgradeSeqBatches.ps1 +++ b/UpgradeSeqBatches.ps1 @@ -1,66 +1,68 @@ -# Copy the current UpdateSequences.bat to all subfolders that have it +# Update subfolders with the latest UpdateSequences and UpdateAllSequences scripts -$sourceFile = "A:\1 Amazon_Active_Projects\3 ProjectStructure\UpdateSequences.bat" +$sourceBat = "A:\1 Amazon_Active_Projects\3 ProjectStructure\UpdateSequences.bat" $sourcePs1 = "A:\1 Amazon_Active_Projects\3 ProjectStructure\UpdateSequences.ps1" +$sourceAllBat = "A:\1 Amazon_Active_Projects\3 ProjectStructure\UpdateAllSequences.bat" -if (-not (Test-Path $sourceFile)) { - Write-Error "Source file not found: $sourceFile" - exit 1 -} +if (-not (Test-Path $sourceBat)) { Write-Error "Source file not found: $sourceBat"; exit 1 } +if (-not (Test-Path $sourcePs1)) { Write-Error "Source PowerShell file not found: $sourcePs1"; exit 1 } +if (-not (Test-Path $sourceAllBat)) { Write-Error "Source file not found: $sourceAllBat"; exit 1 } -if (-not (Test-Path $sourcePs1)) { - Write-Error "Source PowerShell file not found: $sourcePs1" - exit 1 -} +$root = "A:\1 Amazon_Active_Projects" -Write-Host "=== Updating UpdateSequences.bat files ===" -ForegroundColor Cyan -Write-Host "Source .bat: $sourceFile" -ForegroundColor White -Write-Host "Source .ps1: $sourcePs1" -ForegroundColor White -Write-Host "" +$specs = @( + @{ Name = 'UpdateSequences.bat'; Source = $sourceBat }, + @{ Name = 'UpdateSequences.ps1'; Source = $sourcePs1 }, + @{ Name = 'UpdateAllSequences.bat'; Source = $sourceAllBat } +) -# Find all UpdateSequences.bat files -$targetFiles = Get-ChildItem -Path "A:\1 Amazon_Active_Projects" -Recurse -Filter "UpdateSequences.bat" | Where-Object { $_.FullName -ne $sourceFile } +$grandTotal = 0 +$grandUpdated = 0 +$grandFailed = 0 -Write-Host "Found $($targetFiles.Count) target files to update:" -ForegroundColor Yellow -foreach ($file in $targetFiles) { - Write-Host " - $($file.FullName)" -ForegroundColor Gray -} -Write-Host "" +foreach ($spec in $specs) { + Write-Host "=== Updating $($spec.Name) files ===" -ForegroundColor Cyan + Write-Host "Source: $($spec.Source)" -ForegroundColor White + Write-Host "" -$updatedCount = 0 -$failedCount = 0 + $targets = Get-ChildItem -Path $root -Recurse -Filter $spec.Name | Where-Object { $_.FullName -ne $spec.Source } + Write-Host "Found $($targets.Count) target files to update:" -ForegroundColor Yellow + foreach ($t in $targets) { Write-Host " - $($t.FullName)" -ForegroundColor Gray } + Write-Host "" -foreach ($targetFile in $targetFiles) { - $targetDir = $targetFile.Directory.FullName - $targetBat = Join-Path $targetDir "UpdateSequences.bat" - $targetPs1 = Join-Path $targetDir "UpdateSequences.ps1" - - try { - # Copy the .bat file - Copy-Item -Path $sourceFile -Destination $targetBat -Force - Write-Host "✓ Updated: $targetBat" -ForegroundColor Green - - # Copy the .ps1 file - Copy-Item -Path $sourcePs1 -Destination $targetPs1 -Force - Write-Host "✓ Updated: $targetPs1" -ForegroundColor Green - - $updatedCount++ - } - catch { - Write-Host "✗ Failed to update: $targetBat" -ForegroundColor Red - Write-Host " Error: $($_.Exception.Message)" -ForegroundColor Red - $failedCount++ + $updated = 0 + $failed = 0 + foreach ($t in $targets) { + try { + Copy-Item -Path $spec.Source -Destination $t.FullName -Force + Write-Host "✓ Updated: $($t.FullName)" -ForegroundColor Green + $updated++ + } + catch { + Write-Host "✗ Failed to update: $($t.FullName)" -ForegroundColor Red + Write-Host " Error: $($_.Exception.Message)" -ForegroundColor Red + $failed++ + } } + + Write-Host "" + Write-Host "=== $($spec.Name) SUMMARY ===" -ForegroundColor Magenta + Write-Host "Successfully updated: $updated" -ForegroundColor Green + Write-Host "Failed updates: $failed" -ForegroundColor Red + Write-Host "Total targets: $($targets.Count)" -ForegroundColor White + Write-Host "" + + $grandTotal += $targets.Count + $grandUpdated += $updated + $grandFailed += $failed } -Write-Host "" -Write-Host "=== SUMMARY ===" -ForegroundColor Magenta -Write-Host "Successfully updated: $updatedCount" -ForegroundColor Green -Write-Host "Failed updates: $failedCount" -ForegroundColor Red -Write-Host "Total targets: $($targetFiles.Count)" -ForegroundColor White - -if ($failedCount -eq 0) { - Write-Host "`n🎉 All UpdateSequences.bat files have been successfully updated!" -ForegroundColor Green +Write-Host "=== OVERALL SUMMARY ===" -ForegroundColor Magenta +Write-Host "Total targets across all files: $grandTotal" -ForegroundColor White +Write-Host "Total successfully updated: $grandUpdated" -ForegroundColor Green +Write-Host "Total failed: $grandFailed" -ForegroundColor Red +if ($grandFailed -eq 0) { + Write-Host "`nAll files updated successfully." -ForegroundColor Green } else { - Write-Host "`n⚠️ Some files failed to update. Check the errors above." -ForegroundColor Yellow + Write-Host "`nSome updates failed. See errors above." -ForegroundColor Yellow }