[FFmpeg-user] Fwd: Get sample rate in mp3 files

Clayton Macleod cherrytwist at gmail.com
Wed Feb 23 03:00:17 EET 2022

No need to make it any more complicated than need be.  You only need to add
two lines to the existing FOR loop.  The variable %%G contains the current
filename throughout the entire time the loop runs.  As this is the case,
you can simply rename it before you do any of the actual processing in the
loop, and then rename it back once you are finished processing it.  The
variable %%G will still have the current filename assigned to it until the
loop goes through the next iteration.  Take a random group of 10 mp3 files
and copy them into their own directory to do a little test.  Make a
renametest.cmd batch file that contains this, put it in the test directory
with the mp3 files and run it.  You'll see that as the loop runs each time
it renames a single file to temporary.mp3 and then back again.  It will
execute a dir command and then pause so you can see what all the filenames
currently are at each step.

@echo off
for %%G in (*.mp3) do (
echo About to rename %%G to temporary.mp3.
ren "%%G" temporary.mp3
echo ...
echo You should see %%G is now missing from the list, replaced by
echo About to rename temporary.mp3 back to %%G.
ren temporary.mp3 "%%G"
echo You should now see %%G has returned.
pause )

And since that works the way it does, you can simply insert this line at
the start of your loop:

ren "%%G" temporary.mp3

which will rename the current file you're working on.  And then before the
end of your loop you can insert this line to change the name back to the
original one:

ren temporary.mp3 "%%G"

Clayton Macleod
If no one comes from the future to stop you from doing it, then how bad of
a decision can it really be?

More information about the ffmpeg-user mailing list