From 0bffc38f94b357beff789033bdfdb4c9d7caaff8 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 30 Jan 2026 13:40:52 +0000 Subject: [PATCH 1/6] Initial plan From 743e143fcc05cea4441e1e38ef134770f6b1c741 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 30 Jan 2026 13:46:47 +0000 Subject: [PATCH 2/6] Implement verify-files-in-a-folder.ps1 with chunk verification Co-authored-by: jasrasr <92162022+jasrasr@users.noreply.github.com> --- .../verify-files-in-a-folder.ps1 | 123 +++++++++++++++++- 1 file changed, 122 insertions(+), 1 deletion(-) diff --git a/File-Management-Scripts/verify-files-in-a-folder.ps1 b/File-Management-Scripts/verify-files-in-a-folder.ps1 index 4391ede..04c30f3 100644 --- a/File-Management-Scripts/verify-files-in-a-folder.ps1 +++ b/File-Management-Scripts/verify-files-in-a-folder.ps1 @@ -1 +1,122 @@ -# detect files in a folder +<# +.SYNOPSIS + Verifies that files exist in a folder matching a specific pattern. + +.DESCRIPTION + This script verifies that files exist in a folder matching a numbered chunk pattern. + For example, it can verify that files chunk_0001*.txt through chunk_0138*.txt exist, + while ignoring backup files with suffixes like -backup1, -backup2, -backup3, etc. + +.PARAMETER FolderPath + The path to the folder containing the files to verify. This parameter is required. + +.PARAMETER StartChunk + The starting chunk number to verify. Default is 1. + +.PARAMETER EndChunk + The ending chunk number to verify. Default is 138. + +.PARAMETER FileExtension + The file extension to search for (without the dot). Default is "txt". + +.PARAMETER FilePrefix + The prefix used before the chunk number. Default is "chunk_". + +.EXAMPLE + .\verify-files-in-a-folder.ps1 -FolderPath "C:\Backups" + + Verifies that files chunk_0001*.txt through chunk_0138*.txt exist in C:\Backups, + excluding backup files. + +.EXAMPLE + .\verify-files-in-a-folder.ps1 -FolderPath "C:\Backups" -StartChunk 1 -EndChunk 50 -FileExtension csv + + Verifies that files chunk_0001*.csv through chunk_0050*.csv exist in C:\Backups, + excluding backup files. + +.EXAMPLE + .\verify-files-in-a-folder.ps1 -FolderPath "D:\Data" -FilePrefix "data_" -StartChunk 1 -EndChunk 100 + + Verifies that files data_0001*.txt through data_0100*.txt exist in D:\Data, + excluding backup files. + +.NOTES + Files with backup suffixes (e.g., -backup1, -backup2, -backup3) are ignored. + The script returns exit code 0 if all files are found, or 1 if any are missing. +#> + +param( + [Parameter(Mandatory=$true)] + [string]$FolderPath, + + [Parameter(Mandatory=$false)] + [int]$StartChunk = 1, + + [Parameter(Mandatory=$false)] + [int]$EndChunk = 138, + + [Parameter(Mandatory=$false)] + [string]$FileExtension = "txt", + + [Parameter(Mandatory=$false)] + [string]$FilePrefix = "chunk_" +) + +# Verify the folder exists +if (-not (Test-Path -Path $FolderPath)) { + Write-Error "Folder path does not exist: $FolderPath" + exit 1 +} + +Write-Host "Verifying files in folder: $FolderPath" -ForegroundColor Cyan +Write-Host "Looking for files matching pattern: $FilePrefix{0001..$EndChunk}*.$FileExtension" -ForegroundColor Cyan +Write-Host "Excluding files with backup suffixes (-backup1, -backup2, etc.)" -ForegroundColor Cyan +Write-Host "" + +$missingChunks = @() +$foundChunks = @() + +# Loop through each chunk number +for ($i = $StartChunk; $i -le $EndChunk; $i++) { + # Format the chunk number with leading zeros (4 digits) + $chunkNumber = $i.ToString("D4") + + # Build the search pattern for this chunk + $searchPattern = "$FilePrefix$chunkNumber*.$FileExtension" + + # Get all files matching the pattern + $matchingFiles = Get-ChildItem -Path $FolderPath -Filter $searchPattern -File -ErrorAction SilentlyContinue + + # Filter out backup files (files containing -backup followed by numbers) + $nonBackupFiles = $matchingFiles | Where-Object { $_.Name -notmatch '-backup\d+' } + + if ($nonBackupFiles.Count -eq 0) { + $missingChunks += $chunkNumber + Write-Host "✗ Missing: $FilePrefix$chunkNumber*.$FileExtension" -ForegroundColor Red + } else { + $foundChunks += $chunkNumber + Write-Host "✓ Found: $($nonBackupFiles[0].Name)" -ForegroundColor Green + } +} + +# Display summary +Write-Host "" +Write-Host "================================" -ForegroundColor Cyan +Write-Host "Verification Summary" -ForegroundColor Cyan +Write-Host "================================" -ForegroundColor Cyan +Write-Host "Total chunks expected: $($EndChunk - $StartChunk + 1)" -ForegroundColor White +Write-Host "Chunks found: $($foundChunks.Count)" -ForegroundColor Green +Write-Host "Chunks missing: $($missingChunks.Count)" -ForegroundColor Red + +if ($missingChunks.Count -gt 0) { + Write-Host "" + Write-Host "Missing chunk numbers:" -ForegroundColor Yellow + Write-Host ($missingChunks -join ", ") -ForegroundColor Yellow + Write-Host "" + Write-Host "Verification FAILED - Missing files detected" -ForegroundColor Red + exit 1 +} else { + Write-Host "" + Write-Host "Verification PASSED - All files present" -ForegroundColor Green + exit 0 +} From 86b07ed003d5f81dabf11d71f8cc29ea86df8ca4 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 30 Jan 2026 13:48:33 +0000 Subject: [PATCH 3/6] Add validation and improve output messages Co-authored-by: jasrasr <92162022+jasrasr@users.noreply.github.com> --- .../verify-files-in-a-folder.ps1 | 27 +++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/File-Management-Scripts/verify-files-in-a-folder.ps1 b/File-Management-Scripts/verify-files-in-a-folder.ps1 index 04c30f3..5a801f7 100644 --- a/File-Management-Scripts/verify-files-in-a-folder.ps1 +++ b/File-Management-Scripts/verify-files-in-a-folder.ps1 @@ -68,8 +68,27 @@ if (-not (Test-Path -Path $FolderPath)) { exit 1 } +# Validate chunk numbers +if ($StartChunk -le 0) { + Write-Error "StartChunk must be a positive number (greater than 0)" + exit 1 +} + +if ($EndChunk -le 0) { + Write-Error "EndChunk must be a positive number (greater than 0)" + exit 1 +} + +if ($StartChunk -gt $EndChunk) { + Write-Error "StartChunk ($StartChunk) cannot be greater than EndChunk ($EndChunk)" + exit 1 +} + +$startChunkFormatted = $StartChunk.ToString("D4") +$endChunkFormatted = $EndChunk.ToString("D4") + Write-Host "Verifying files in folder: $FolderPath" -ForegroundColor Cyan -Write-Host "Looking for files matching pattern: $FilePrefix{0001..$EndChunk}*.$FileExtension" -ForegroundColor Cyan +Write-Host "Looking for files matching pattern: $FilePrefix$startChunkFormatted to $FilePrefix$endChunkFormatted*.$FileExtension" -ForegroundColor Cyan Write-Host "Excluding files with backup suffixes (-backup1, -backup2, etc.)" -ForegroundColor Cyan Write-Host "" @@ -95,7 +114,11 @@ for ($i = $StartChunk; $i -le $EndChunk; $i++) { Write-Host "✗ Missing: $FilePrefix$chunkNumber*.$FileExtension" -ForegroundColor Red } else { $foundChunks += $chunkNumber - Write-Host "✓ Found: $($nonBackupFiles[0].Name)" -ForegroundColor Green + if ($nonBackupFiles.Count -eq 1) { + Write-Host "✓ Found: $($nonBackupFiles[0].Name)" -ForegroundColor Green + } else { + Write-Host "✓ Found: $($nonBackupFiles[0].Name) (+$($nonBackupFiles.Count - 1) more)" -ForegroundColor Green + } } } From 643e5f48206dcfba67b6560b6a08b2b86a8a280f Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 30 Jan 2026 13:50:15 +0000 Subject: [PATCH 4/6] Fix error handling consistency and improve backup file pattern Co-authored-by: jasrasr <92162022+jasrasr@users.noreply.github.com> --- File-Management-Scripts/verify-files-in-a-folder.ps1 | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/File-Management-Scripts/verify-files-in-a-folder.ps1 b/File-Management-Scripts/verify-files-in-a-folder.ps1 index 5a801f7..d137010 100644 --- a/File-Management-Scripts/verify-files-in-a-folder.ps1 +++ b/File-Management-Scripts/verify-files-in-a-folder.ps1 @@ -64,23 +64,23 @@ param( # Verify the folder exists if (-not (Test-Path -Path $FolderPath)) { - Write-Error "Folder path does not exist: $FolderPath" + Write-Host "Error: Folder path does not exist: $FolderPath" -ForegroundColor Red exit 1 } # Validate chunk numbers if ($StartChunk -le 0) { - Write-Error "StartChunk must be a positive number (greater than 0)" + Write-Host "Error: StartChunk must be a positive number (greater than 0)" -ForegroundColor Red exit 1 } if ($EndChunk -le 0) { - Write-Error "EndChunk must be a positive number (greater than 0)" + Write-Host "Error: EndChunk must be a positive number (greater than 0)" -ForegroundColor Red exit 1 } if ($StartChunk -gt $EndChunk) { - Write-Error "StartChunk ($StartChunk) cannot be greater than EndChunk ($EndChunk)" + Write-Host "Error: StartChunk ($StartChunk) cannot be greater than EndChunk ($EndChunk)" -ForegroundColor Red exit 1 } @@ -106,8 +106,8 @@ for ($i = $StartChunk; $i -le $EndChunk; $i++) { # Get all files matching the pattern $matchingFiles = Get-ChildItem -Path $FolderPath -Filter $searchPattern -File -ErrorAction SilentlyContinue - # Filter out backup files (files containing -backup followed by numbers) - $nonBackupFiles = $matchingFiles | Where-Object { $_.Name -notmatch '-backup\d+' } + # Filter out backup files (files containing -backup followed by numbers before the extension) + $nonBackupFiles = $matchingFiles | Where-Object { $_.Name -notmatch '-backup\d+\.' } if ($nonBackupFiles.Count -eq 0) { $missingChunks += $chunkNumber From 4743d24e5ec716d63fb46ddebc8ac14d3db15eef Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 30 Jan 2026 13:52:01 +0000 Subject: [PATCH 5/6] Add parameter validation and fix backup file regex pattern Co-authored-by: jasrasr <92162022+jasrasr@users.noreply.github.com> --- .../verify-files-in-a-folder.ps1 | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/File-Management-Scripts/verify-files-in-a-folder.ps1 b/File-Management-Scripts/verify-files-in-a-folder.ps1 index d137010..e874bf6 100644 --- a/File-Management-Scripts/verify-files-in-a-folder.ps1 +++ b/File-Management-Scripts/verify-files-in-a-folder.ps1 @@ -68,6 +68,18 @@ if (-not (Test-Path -Path $FolderPath)) { exit 1 } +# Validate file extension +if ($FileExtension -match '[\\/:*?"<>|]') { + Write-Host "Error: FileExtension contains invalid characters. Use only valid filename characters without special symbols." -ForegroundColor Red + exit 1 +} + +# Validate file prefix +if ($FilePrefix -match '[\\/:*?"<>|]') { + Write-Host "Error: FilePrefix contains invalid characters. Use only valid filename characters without wildcards or special symbols." -ForegroundColor Red + exit 1 +} + # Validate chunk numbers if ($StartChunk -le 0) { Write-Host "Error: StartChunk must be a positive number (greater than 0)" -ForegroundColor Red @@ -106,8 +118,10 @@ for ($i = $StartChunk; $i -le $EndChunk; $i++) { # Get all files matching the pattern $matchingFiles = Get-ChildItem -Path $FolderPath -Filter $searchPattern -File -ErrorAction SilentlyContinue - # Filter out backup files (files containing -backup followed by numbers before the extension) - $nonBackupFiles = $matchingFiles | Where-Object { $_.Name -notmatch '-backup\d+\.' } + # Filter out backup files (files containing -backup followed by numbers immediately before the extension) + $escapedExtension = [regex]::Escape($FileExtension) + $backupPattern = "-backup\d+\.$escapedExtension$" + $nonBackupFiles = $matchingFiles | Where-Object { $_.Name -notmatch $backupPattern } if ($nonBackupFiles.Count -eq 0) { $missingChunks += $chunkNumber From 2782077dd13435509a9b8910ab9a150444b9a6f1 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 30 Jan 2026 13:53:20 +0000 Subject: [PATCH 6/6] Improve error message clarity for parameter validation Co-authored-by: jasrasr <92162022+jasrasr@users.noreply.github.com> --- File-Management-Scripts/verify-files-in-a-folder.ps1 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/File-Management-Scripts/verify-files-in-a-folder.ps1 b/File-Management-Scripts/verify-files-in-a-folder.ps1 index e874bf6..631263d 100644 --- a/File-Management-Scripts/verify-files-in-a-folder.ps1 +++ b/File-Management-Scripts/verify-files-in-a-folder.ps1 @@ -70,13 +70,13 @@ if (-not (Test-Path -Path $FolderPath)) { # Validate file extension if ($FileExtension -match '[\\/:*?"<>|]') { - Write-Host "Error: FileExtension contains invalid characters. Use only valid filename characters without special symbols." -ForegroundColor Red + Write-Host "Error: FileExtension contains invalid characters. Disallowed characters: \ / : * ? `" < > |" -ForegroundColor Red exit 1 } # Validate file prefix if ($FilePrefix -match '[\\/:*?"<>|]') { - Write-Host "Error: FilePrefix contains invalid characters. Use only valid filename characters without wildcards or special symbols." -ForegroundColor Red + Write-Host "Error: FilePrefix contains invalid characters. Disallowed characters: \ / : * ? `" < > |" -ForegroundColor Red exit 1 }