I'm new to programming and trying to convert WAV, MP3, and OGG files so they're recognized by iTunes. I tried running this command in PowerShell:
for (%f in (*.wav *.mp3 *.ogg)) {do {ffmpeg -i "%f" -b:a 128k -ar 44100 "%~nf_new.mp3"}}
PowerShell reports "Missing while or until keyword in do loop." What is the correct way to run this conversion?
3 Answers
The error happens because PowerShell interprets `do` as the beginning of a do/while or do/until loop, but your command never provides the required `while` or `until` condition. More importantly, `%f` and `%~nf` are batch-file variables, not PowerShell variables. Use one shell’s syntax consistently instead of combining the two.
The command mixes Windows batch syntax with PowerShell syntax. In a regular Command Prompt or batch file, the loop would be written without the braces: `for %f in (*.wav *.mp3 *.ogg) do ffmpeg -i "%f" -b:a 128k -ar 44100 "%~nf_new.mp3"`. If you put it in a `.bat` file, use `%%f` instead of `%f`. There’s no need for a `do`/`while` loop here.
Since your terminal opens PowerShell, use PowerShell’s file enumeration instead:
`Get-ChildItem -File -Include *.wav,*.mp3,*.ogg | ForEach-Object { ffmpeg -i $_.FullName -b:a 128k -ar 44100 (Join-Path $_.DirectoryName ($_.BaseName + '_new.mp3')) }`
Run it from the folder containing the audio files. `Get-ChildItem` finds the files, and `ForEach-Object` runs FFmpeg once for each one.

That explains it—I had combined an old batch tutorial with a little C++ syntax from memory. I’ll use the PowerShell version since that’s what opens in the folder.