Question

I have thousands of file pairs that I need zipped into archives. Currently, each file pair (*.mp3 & *.cdg) have the same name (aside from the extension). Each of the file pairs reside in sub-directories inside the primary directory. I want to leave each archive in the same sub-directory that the file pair was already. I currently am using the following cmd command, but it creates the archives in the primary directory, and then "cannot find" either *.mp3 or *.cdg.

FOR /r %F IN (*.mp3) DO "C:\Program Files\7-Zip\7Z.exe" a "%~nF.zip" "%~nF.mp3" "%~nF.cdg"

What do I need to modify to leave each archive in the original file's sub-directory without creating 140+ batch files for each sub-directory?

Was it helpful?

Solution

You need to include the path info modifiers: d=drive, p=path, and for the mp3 f=full path

FOR /r %F IN (*.mp3) DO "C:\Program Files\7-Zip\7Z.exe" a "%~dpnF.zip" "%~fF" "%~dpnF.cdg"
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top