upseqbatches updates all

This commit is contained in:
Nathan
2025-08-26 15:59:26 -06:00
parent 7021458963
commit c086f4b031
2 changed files with 113 additions and 52 deletions

View File

@@ -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**_
<think><details><summary>Thought Process</summary>**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: Ill 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, Ill 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 Ill restructure my approach into three loops while maintaining readability. First, Ill define the source variables and check their existence—failing if any are missing.
Next, Ill 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, Ill restrict the new changes to only copy where the file already exists.
Ill provide a summary for each file type and utilize the existing error handling. Now, Ill edit UpgradeSeqBatches.ps1 and make the echoed messages more concise.
I'll apply the patch and run read_lints, checking for any flagged issues. Its 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**
Ill include a brief micro-update just before the tool calls, and well apply the patch as planned. Since were modifying an existing script, Ill skip creating a todo list.
To handle edge cases, Ill structure the code to loop through an array of file specifications. Ill set up item details for UpdateSequences.bat, UpdateSequences.ps1, and UpdateAllSequences.bat.
For each item, Ill gather targets using `Get-ChildItem` and print the found counts. Then, Ill copy each file with proper error handling and keep track of successes and failures. Finally, Ill print a summary while ensuring consistent formatting with colored outputs.</details></think>
---
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.
---

View File

@@ -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
}