I am using mkvmerge to extract audio from multiple files. When doing that, I want to rename the extracted files so it is easier for me to merge them later.
My command right now is this
for /f "delims=" %%A IN ('dir /b *.mkv') DO mkvextract tracks "%%A" 2:F:\%%~nA.ogg
Which extracts an audio from a file say "x1.mkv" to "x1.ogg"
What I want to do is, rename the audio file (x1.ogg) to the name of another file from another folder. Kinda like this command (Which I know is wrong, I'm trying to tell what I want to achieve):
for /f "delims=" %%A IN ('dir /b *.mkv') && %%B in ('dir "F:\Show" /b *.mkv') DO mkvextract tracks "%%A" 2:F:\%%~nB.ogg
Which Takes a file from my current directory (%%A) , but the extracted audio will have the name of the corresponding file in another directory (%%B).
Thus,
x1.mkv => y1.ogg
x2.mkv => y2.ogg and so on..
So how do I type the FOR command in which 2 variables have names of files of 2 different directories?
Thanks!
You would need to change the setting of
destdir
to suit your circumstances.The required commands are merely
ECHO
ed for testing purposes. After you've verified that the commands are correct, delete the stringECHO(
which appears before your command to actually execute the commands."filter" any line from the directory list containing any character, and number the line with a preceding
#:
. This has the effect of simply producing the same list, but numbered with#:
preceding.Tokenise each line into
%%A
and%%B
using the separating:
so the number goes to%%A
and the filename to%%B
.With each
%%A,%%B
, do the same trick to the other directory, this time producing%%D,%%E
, then if the line numbers match, execute your command with the appropriate selection of elements from the variables.