Use today's YYYYMMDD subfolder for PDFs, archive whole folder on success

This commit is contained in:
2026-06-29 19:47:38 -05:00
parent a26eb39ccb
commit 54baaf52e7
3 changed files with 87 additions and 64 deletions
+18 -9
View File
@@ -1,7 +1,8 @@
# Run FTP upload for every practice folder found under this root.
# Searches recursively for ftp-config.ini and uploads PDFs from each folder.
# Searches recursively for ftp-config.ini and uploads PDFs from today's date folder in each.
$rootDir = Split-Path -Parent $MyInvocation.MyCommand.Path
$today = Get-Date -Format "yyyyMMdd"
$configs = Get-ChildItem -Path $rootDir -Recurse -Filter "ftp-config.ini"
if ($configs.Count -eq 0) {
@@ -10,6 +11,7 @@ if ($configs.Count -eq 0) {
}
Write-Host ""
Write-Host "Date: $today"
Write-Host "Found $($configs.Count) practice folder(s)" -ForegroundColor Cyan
Write-Host ("=" * 50)
@@ -20,10 +22,17 @@ $totalSkip = 0
foreach ($configFile in $configs) {
$folderDir = $configFile.DirectoryName
$folderName = Split-Path -Leaf $folderDir
$dateDir = Join-Path $folderDir $today
Write-Host ""
Write-Host "[ $folderName ]" -ForegroundColor Cyan
if (-not (Test-Path $dateDir)) {
Write-Host " No folder for today ($today) — skipping." -ForegroundColor Gray
$totalSkip++
continue
}
# Parse config
$config = @{}
foreach ($line in Get-Content $configFile.FullName) {
@@ -50,10 +59,10 @@ foreach ($configFile in $configs) {
New-Item -ItemType Directory -Path $archiveDir | Out-Null
}
$pdfs = Get-ChildItem -Path $folderDir -Filter "*.pdf" -File
$pdfs = Get-ChildItem -Path $dateDir -Filter "*.pdf" -File
if ($pdfs.Count -eq 0) {
Write-Host " No PDFs to upload." -ForegroundColor Gray
Write-Host " No PDFs in $today\ — skipping." -ForegroundColor Gray
$totalSkip++
continue
}
@@ -85,7 +94,6 @@ foreach ($configFile in $configs) {
$resp = $req.GetResponse()
$resp.Close()
Move-Item -Path $pdf.FullName -Destination (Join-Path $archiveDir $pdf.Name) -Force
Write-Host " uploaded" -ForegroundColor Green
$ok++
}
@@ -98,17 +106,18 @@ foreach ($configFile in $configs) {
$totalOk += $ok
$totalFail += $fail
if ($fail -eq 0) {
Write-Host " $ok file(s) uploaded." -ForegroundColor Green
} else {
Write-Host " $ok uploaded, $fail failed." -ForegroundColor Yellow
if ($fail -eq 0 -and $ok -gt 0) {
Move-Item -Path $dateDir -Destination (Join-Path $archiveDir $today) -Force
Write-Host " $ok file(s) uploaded. Folder $today\ archived." -ForegroundColor Green
} elseif ($fail -gt 0) {
Write-Host " $ok uploaded, $fail failed (left in $today\ for retry)." -ForegroundColor Yellow
}
}
Write-Host ""
Write-Host ("=" * 50)
if ($totalFail -eq 0) {
Write-Host "All done: $totalOk file(s) uploaded across $($configs.Count) folder(s)." -ForegroundColor Green
Write-Host "All done: $totalOk file(s) uploaded across $($configs.Count - $totalSkip) folder(s)." -ForegroundColor Green
} else {
Write-Host "Done: $totalOk uploaded, $totalFail failed, $totalSkip skipped." -ForegroundColor Yellow
}