How can I convert multiple audio files with FFmpeg in PowerShell?

August 5, 2026 3 answers
Asked by MellowCedar42
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?

Answers

QuietMaple19
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.
Reply to this answer
BrightHarbor7
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.
Reply to this answer
SilverPine8
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.

MellowCedar42: 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.

Reply to this answer

Add your answer

Answers are reviewed before publication.

Related Discussions