upseqbatches updates all
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user