2

After a hard study, I have created a batch file:

for /R  D:\storytelling\MusicFiles %%a in (*.3gp) do ffmpeg -i %%a -y %%~na.mp3

However, it can't reach my goal since the scenario is a little different here:

Here is my directory structure: enter image description here

I have several directories under a certain path:D:\storytelling\MusicFiles\ and new directories could be created by another application. And I put ffmpeg.exe file in this path: D:\storytelling\MusicFiles\.
Also, In each directory, I have hundreds of .3gp files, and my target is to convert them to .mp3 in the directory where they used to stay at.
But this script

for /R  D:\storytelling\MusicFiles %%a in (*.3gp) do ffmpeg -i %%a -y %%~na.mp3

would convert every .3gp file in each directory to the path: D:\storytelling\MusicFiles\

It leads to:enter image description here
But I want the publicUser_XXX.mp3 files are still in the directory publicUser and after conversion all the files remain in their original directory. The only change is that I got new a media copy with different media format like: enter image description here

Please help and give me some advise.

1 Answer 1

2

Try this:

@echo off
for /R  D:\storytelling\MusicFiles %%a in (*.3gp) do ffmpeg -i "%%a" -y "%%~dpna.mp3"
Sign up to request clarification or add additional context in comments.

8 Comments

Great, it works!. May I ask you why don't you add quotation mark to like: "(*.3gpp)" and why did you add that to %%~dpna.mp3, what's the timing? And... What does %%~dpna actually do?
Btw: Stackoverflow already provides a button to let you upload the image.
@Stallman - thanks for replying - I found the upload button.
It's always good practice to use "path\filename" because then you don't have to redesign the code later for long filenames. (*.3gp) part of a for-in-do command will never need quotes. There are many cases in batch files where exemptions-to-the-rule apply and learning them slowly as you need them is a good way. In general always double quote "c:\folder\filename.ext"
%%~n is the part that applies the name part of the metavariable and the a is the suffix because you used %%a. If you used %%B then it would be %%~nB (case sensitive). See the for /? help on the last page for a list.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.