param ( [Parameter(Mandatory=$true)] [string]$dir ) # Check if the directory exists if (!(Test-Path -Path $dir -PathType Container)) { Write-Host "Directory $dir does not exist." exit 1 } # Get all .webp files $files = Get-ChildItem -Path $dir -Filter "*.webp" # Process each file foreach ($file in $files) { $inputFile = $file.FullName $outputFile = Join-Path $file.DirectoryName ($file.BaseName + ".png") # Run ffmpeg command & ffmpeg -i $inputFile $outputFile # Check if the conversion was successful if ($?) { # Delete the input .webp file Remove-Item -Path $inputFile } else { Write-Host "ffmpeg failed for $inputFile. Continuing with next file." } }