From a057ab0d1d09cec7a6b971c0b6e371bc0ab7a6b1 Mon Sep 17 00:00:00 2001 From: Claude Toupin Date: Tue, 9 Jun 2026 20:50:09 -0400 Subject: [PATCH] Add wildcard support to Get-VideoInfo.ps1 for processing multiple video files with pattern matching and sequential metadata display --- Get-VideoInfo.ps1 | 42 ++++++++++++++++++++++++++++++++++-------- 1 file changed, 34 insertions(+), 8 deletions(-) diff --git a/Get-VideoInfo.ps1 b/Get-VideoInfo.ps1 index a04189a..7a5ac25 100644 --- a/Get-VideoInfo.ps1 +++ b/Get-VideoInfo.ps1 @@ -3,6 +3,8 @@ Extracts and displays video metadata from the comment tag in a video file's format metadata. .PARAMETER Video Path to the input video file. Can be absolute or relative to current directory. + Supports Windows wildcards (* and ?) to match multiple files. When wildcards are used, + metadata is extracted and displayed for each matching file sequentially. .PARAMETER Full When present, outputs the parsed comment metadata as JSON. .DESCRIPTION @@ -23,17 +25,39 @@ $ErrorActionPreference = 'Stop' [Console]::OutputEncoding = [System.Text.Encoding]::UTF8 $OutputEncoding = [System.Text.Encoding]::UTF8 -$VideoPath = $Video - -if (-not (Test-Path -LiteralPath $VideoPath)) { - Write-Error ('Video file not found: {0}' -f $VideoPath) - exit 1 +# Resolve video paths, supporting wildcards +$videoPaths = @() +if ($Video -match '[*?]') { + # Wildcard pattern - use Get-ChildItem to resolve + $resolvedFiles = Get-ChildItem -Path $Video -File -ErrorAction SilentlyContinue + if (-not $resolvedFiles) { + Write-Error ('No files matched wildcard pattern: {0}' -f $Video) + exit 1 + } + $videoPaths = $resolvedFiles | Select-Object -ExpandProperty FullName +} else { + # Single file path (literal) + if (-not (Test-Path -LiteralPath $Video)) { + Write-Error ('Video file not found: {0}' -f $Video) + exit 1 + } + $videoPaths = @($Video) } $PSNativeCommandUseErrorActionPreference = $false +$firstFile = $true +foreach ($VideoPath in $videoPaths) { + # Add separator between files (but not before the first one) + if (-not $firstFile) { + Write-Output '' + Write-Output '========================================' + Write-Output '' + } + $firstFile = $false + try { - $ffprobeOutput = & ffprobe -v quiet -print_format json -show_format -show_streams -- $VideoPath 2>&1 + $ffprobeOutput = & ffprobe -v quiet -print_format json -show_format -show_streams -- "$VideoPath" 2>&1 $ffprobeExit = $LASTEXITCODE if ($ffprobeExit -ne 0) { @@ -191,6 +215,8 @@ try { Write-Output '----------------------------------------' } catch { - Write-Error ('Unexpected error: {0}' -f $_.Exception.Message) - exit 1 + Write-Error ('Unexpected error processing {0}: {1}' -f $VideoPath, $_.Exception.Message) + # Continue to next file instead of exiting + continue +} }