r/PowerShell • u/Norest4themisfits • May 27 '26
Question missing while do loop error
hello! i know nothing about code and I'm just trying to convert some music files so itunes recognizes them, i keep getting an error on the following script
for (%f in (*.wav *.mp3 *.ogg)) {do {ffmpeg -i "%f" -b:a 128k -ar 44100 "%~nf_new.mp3"}}
the error is as follows
At line:1 char:88
+ ... .mp3 *.ogg)) {do {ffmpeg -i "%f" -b:a 128k -ar 44100 "%~nf_new.mp3"}}
+ ~
Missing while or until keyword in do loop.
+ CategoryInfo : ParserError: (:) [], ParentContainsErrorRecordException
+ FullyQualifiedErrorId : MissingWhileOrUntilInDoWhile
knowing nothing about programming I have no idea how to fix it or what to add. please help!
2
u/MyOtherSide1984 May 27 '26
Yeah don't run stuff you don't understand. If it came from ChatGPT or some random forum, you can't really trust it and could easily cause a lot of issues real fast.
2
u/BoredTech127001 May 27 '26
Your trying to run batch file commands in powershell. You should just open a command prompt and paste that code, don't run it in powershell.
3
u/-Shants- May 27 '26
It looks like you smashed together a for loop and a do/while loop. Maybe don’t do that and look up how to properly structure a for loop. I doubt the do/while is even needed
2
u/Cadder May 28 '26
Uh, yeah. that's not proper powershell for a start. you don't use % in PS.
%f is a variable name for a direct command line.
Double the % if you want to do it in a batch/cmd file. ie %%f
..then get the syntax right:
for %f in (*.wav *.mp3 *.ogg) do ffmpeg -i "%f" -b:a 128k -ar 44100 "%~nf_new.mp3"
OR if you really need to do it in Powershell:
Get-ChildItem *.wav,*.mp3,*.ogg | ForEach-Object {ffmpeg -i "$_" -b:a 128k -ar 44100 $($_.BaseName)_new.mp3"}
1
u/BlackV May 27 '26
there are post in this sub using ffmpeg and powershell
what you have posted is cmd/batch and would need to be run fromt here
recommend, finding the posts and move it to powershell code instead
1
u/dodexahedron May 27 '26
To get help on powershell loops, run these commands:
Get-Help about_While
Get-Help about_For
Get-Help about_ForEach
0
u/brazzala May 28 '26
Regex is not easy…
0
u/[deleted] May 27 '26
[deleted] — view deleted comment